~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to kde/src/widgets/TranslucentButtons.cpp

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2012-02-18 21:47:09 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120218214709-6362d71gqdsdkrj5
Tags: 1.0.2-1
* New upstream release
  - remove logging patch (applied upstream)
  - update s390 patch since it was partially applied upstream
* Include the Evolution plugin as a separate binary package

* Fix compilation issues on SH4 (closes: #658987)
* Merge Ubuntu's binutils-gold linking fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "TranslucentButtons.h"
 
2
 
 
3
#include <QtGui/QPainter>
 
4
#include <KDebug>
 
5
 
 
6
#include <QtCore/QTimer>
 
7
#include <QDragEnterEvent>
 
8
#include <QDragMoveEvent>
 
9
#include <QDragLeaveEvent>
 
10
#include <QMimeData>
 
11
 
 
12
///Constructor
 
13
TranslucentButtons::TranslucentButtons(QWidget* parent):QPushButton(parent),m_enabled(true),m_pTimer(0),m_CurrentState(0),m_pImg(0)
 
14
{
 
15
   setAcceptDrops(true);
 
16
   m_CurrentColor = "black";
 
17
   m_CurrentColor.setAlpha(0);
 
18
}
 
19
 
 
20
///Destructor
 
21
TranslucentButtons::~TranslucentButtons()
 
22
{
 
23
 
 
24
}
 
25
 
 
26
///How to paint
 
27
void TranslucentButtons::paintEvent(QPaintEvent* event)
 
28
{
 
29
   Q_UNUSED(event)
 
30
   QPainter customPainter(this);
 
31
   customPainter.setBackground(m_CurrentColor);
 
32
   customPainter.setBrush(m_CurrentColor);
 
33
   customPainter.setPen(Qt::NoPen);
 
34
   customPainter.drawRoundedRect(rect(), 10, 10);
 
35
   customPainter.setPen(m_Pen);
 
36
 
 
37
   if (m_pImg) {
 
38
      customPainter.drawImage(QRect(QPoint(rect().x()+rect().width()-50,10),QSize(40,rect().height()-20)),*m_pImg, QRectF(m_pImg->rect()));
 
39
   }
 
40
 
 
41
   QFont font = customPainter.font();
 
42
   font.setBold(true);
 
43
   customPainter.setFont(font);
 
44
   customPainter.drawText (rect(), Qt::AlignVCenter|Qt::AlignHCenter, text().replace("&","") );
 
45
}
 
46
 
 
47
///Override the visibility toggler
 
48
void TranslucentButtons::setVisible(bool enabled)
 
49
{
 
50
   kDebug() << "Enabling!";
 
51
   if (m_enabled != enabled) {
 
52
      if (m_pTimer) {
 
53
         m_pTimer->stop();
 
54
         disconnect(m_pTimer);
 
55
      }
 
56
      m_pTimer = new QTimer(this); //TODO LEAK
 
57
      connect(m_pTimer, SIGNAL(timeout()), this, SLOT(changeVisibility()));
 
58
      m_step = 0;
 
59
      m_CurrentColor = "black";
 
60
      m_CurrentColor.setAlpha(0);
 
61
      repaint();
 
62
      m_pTimer->start(10);
 
63
      raise();
 
64
   }
 
65
   m_enabled = enabled;
 
66
   QWidget::setVisible(enabled);
 
67
}
 
68
 
 
69
///Step by step animation
 
70
void TranslucentButtons::changeVisibility()
 
71
{
 
72
   m_step++;
 
73
   m_CurrentColor.setAlpha(0.1*m_step*m_step);
 
74
   repaint();
 
75
   if (m_step >= 35)
 
76
      m_pTimer->stop();
 
77
}
 
78
 
 
79
void TranslucentButtons::dragEnterEvent ( QDragEnterEvent *e )
 
80
{
 
81
   e->ignore();
 
82
}
 
83
 
 
84
void TranslucentButtons::dragMoveEvent  ( QDragMoveEvent  *e )
 
85
{
 
86
   e->ignore();
 
87
}
 
88
 
 
89
void TranslucentButtons::dragLeaveEvent ( QDragLeaveEvent *e )
 
90
{
 
91
   e->ignore();
 
92
}
 
93
 
 
94
///Propagate the mime data
 
95
///@note This propagate like this: button -> tree item -> treewidget
 
96
void TranslucentButtons::dropEvent(QDropEvent *e)
 
97
{
 
98
   kDebug() << "Drop accepted";
 
99
   emit dataDropped((QMimeData*)e->mimeData());
 
100
}
 
101
 
 
102
///Set the state when the user hover the widget
 
103
///@note This is not called directly to avoid a Qt bug/limitation
 
104
void TranslucentButtons::setHoverState(bool hover)
 
105
{
 
106
   if (hover != m_CurrentState) {
 
107
      if (hover) {
 
108
         int alpha = m_CurrentColor.alpha();
 
109
         m_CurrentColor = "grey";
 
110
         m_CurrentColor.setAlpha(alpha);
 
111
         m_Pen.setColor("black");
 
112
      }
 
113
      else {
 
114
         int alpha = m_CurrentColor.alpha();
 
115
         m_CurrentColor = "black";
 
116
         m_CurrentColor.setAlpha(alpha);
 
117
         m_Pen.setColor("white");
 
118
      }
 
119
      repaint();
 
120
      m_CurrentState = hover;
 
121
   }
 
122
}
 
123
 
 
124
///Set the button pixmap
 
125
void TranslucentButtons::setPixmap(QImage* img)
 
126
{
 
127
   m_pImg = img;
 
128
}
 
 
b'\\ No newline at end of file'