diff options
| author | Manjeet Dahiya <manjeetdahiya@gmail.com> | 2010-09-08 09:23:18 +0000 |
|---|---|---|
| committer | Manjeet Dahiya <manjeetdahiya@gmail.com> | 2010-09-08 09:23:18 +0000 |
| commit | da88f5f0bb5e73bc69bf7ed3962691622b1ae4f9 (patch) | |
| tree | c3686f7649785a2bfcc2c637a1588acdb8a721e8 /examples/GuiClient/avatarWidget.cpp | |
| parent | 3431f5a37174b7eb8490672686db68df2b48e35f (diff) | |
| download | qxmpp-da88f5f0bb5e73bc69bf7ed3962691622b1ae4f9.tar.gz | |
add Gui Client example
Diffstat (limited to 'examples/GuiClient/avatarWidget.cpp')
| -rw-r--r-- | examples/GuiClient/avatarWidget.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/GuiClient/avatarWidget.cpp b/examples/GuiClient/avatarWidget.cpp new file mode 100644 index 00000000..535e1d63 --- /dev/null +++ b/examples/GuiClient/avatarWidget.cpp @@ -0,0 +1,41 @@ +#include "avatarWidget.h"
+#include <QtGui/QPainter>
+
+avatarWidget::avatarWidget(QWidget* parent)
+ : QPushButton(parent)
+{
+}
+
+void avatarWidget::paintEvent(QPaintEvent* event)
+{
+ Q_UNUSED(event);
+ QPainter painter(this);
+
+ QRect r = rect();
+
+ QPixmap pixmap = icon().pixmap(sizeHint(), QIcon::Normal, QIcon::On);
+ if(pixmap.isNull())
+ pixmap = QPixmap(":/icons/resource/avatar.png");
+ QRect pixRect(0, 0, 32, 32);
+ pixRect.moveCenter(r.center());
+ painter.drawPixmap(pixRect, pixmap);
+
+ if(underMouse() && !isDown())
+ {
+ painter.drawRect(pixRect.adjusted(0, 0, -1, -1));
+ QColor col(Qt::white);
+ col.setAlpha(80);
+ painter.fillRect(pixRect.adjusted(0, 0, -1, -1), col);
+ }
+ if(isDown())
+ {
+ QColor col(Qt::white);
+ col.setAlpha(50);
+ painter.drawRect(pixRect.adjusted(1, 1, -2, -2));
+ }
+}
+
+QSize avatarWidget::sizeHint() const
+{
+ return QSize(32, 32);
+}
|
