| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 2007 Licq developers |
|---|
| 5 | * |
|---|
| 6 | * Licq is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * Licq is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with Licq; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include "dockiconwidget.h" |
|---|
| 22 | |
|---|
| 23 | #include "config.h" |
|---|
| 24 | |
|---|
| 25 | #include <QCloseEvent> |
|---|
| 26 | #include <QBitmap> |
|---|
| 27 | #include <QMenu> |
|---|
| 28 | #include <QPainter> |
|---|
| 29 | |
|---|
| 30 | #include "helpers/support.h" |
|---|
| 31 | |
|---|
| 32 | #include "dockicon.h" |
|---|
| 33 | |
|---|
| 34 | using namespace LicqQtGui; |
|---|
| 35 | |
|---|
| 36 | DockIconWidget::DockIconWidget(QMenu* menu) |
|---|
| 37 | : QWidget(), |
|---|
| 38 | myMenu(menu), |
|---|
| 39 | myFace(NULL) |
|---|
| 40 | { |
|---|
| 41 | resize(64, 64); |
|---|
| 42 | setAttribute(Qt::WA_NoSystemBackground, true); |
|---|
| 43 | setAttribute(Qt::WA_AlwaysShowToolTips, true); |
|---|
| 44 | Support::setWidgetProps(this, "DockIconWidget"); |
|---|
| 45 | myHandler = Support::dockWindow(winId()); |
|---|
| 46 | show(); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | DockIconWidget::~DockIconWidget() |
|---|
| 50 | { |
|---|
| 51 | Support::undockWindow(winId(), myHandler); |
|---|
| 52 | delete myFace; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | void DockIconWidget::setFace(QPixmap* newFace, bool updateMask) |
|---|
| 56 | { |
|---|
| 57 | if (newFace == NULL || newFace->isNull()) |
|---|
| 58 | return; |
|---|
| 59 | |
|---|
| 60 | delete myFace; |
|---|
| 61 | myFace = new QPixmap(*newFace); |
|---|
| 62 | resize(myFace->size()); |
|---|
| 63 | if (updateMask) |
|---|
| 64 | setMask(myFace->mask()); |
|---|
| 65 | update(); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | QPixmap* DockIconWidget::face() |
|---|
| 69 | { |
|---|
| 70 | if (myFace == NULL) |
|---|
| 71 | return NULL; |
|---|
| 72 | |
|---|
| 73 | return new QPixmap(*myFace); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | void DockIconWidget::closeEvent(QCloseEvent* event) |
|---|
| 77 | { |
|---|
| 78 | event->ignore(); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | void DockIconWidget::mousePressEvent(QMouseEvent* event) |
|---|
| 82 | { |
|---|
| 83 | switch (event->button()) |
|---|
| 84 | { |
|---|
| 85 | case Qt::LeftButton: |
|---|
| 86 | emit clicked(); |
|---|
| 87 | break; |
|---|
| 88 | |
|---|
| 89 | case Qt::MidButton: |
|---|
| 90 | emit middleClicked(); |
|---|
| 91 | break; |
|---|
| 92 | |
|---|
| 93 | case Qt::RightButton: |
|---|
| 94 | myMenu->popup(event->globalPos()); |
|---|
| 95 | break; |
|---|
| 96 | |
|---|
| 97 | default: |
|---|
| 98 | break; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | void DockIconWidget::paintEvent(QPaintEvent* event) |
|---|
| 103 | { |
|---|
| 104 | if (myFace == NULL) |
|---|
| 105 | return; |
|---|
| 106 | |
|---|
| 107 | event->ignore(); |
|---|
| 108 | QPainter painter(this); |
|---|
| 109 | painter.drawPixmap(0, 0, *myFace); |
|---|
| 110 | } |
|---|