Changeset 6058 for branches/qt-gui_qt4/src/dockicons
- Timestamp:
- 01/24/08 21:40:25 (10 months ago)
- Location:
- branches/qt-gui_qt4/src/dockicons
- Files:
-
- 11 modified
-
CMakeLists.txt (modified) (2 diffs)
-
defaultdockicon.cpp (modified) (3 diffs)
-
defaultdockicon.h (modified) (3 diffs)
-
dockicon.cpp (modified) (10 diffs)
-
dockicon.h (modified) (7 diffs)
-
dockiconwidget.cpp (modified) (2 diffs)
-
dockiconwidget.h (modified) (4 diffs)
-
systemtrayicon.cpp (modified) (5 diffs)
-
systemtrayicon.h (modified) (2 diffs)
-
themeddockicon.cpp (modified) (7 diffs)
-
themeddockicon.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/qt-gui_qt4/src/dockicons/CMakeLists.txt
r5777 r6058 2 2 set(dockicons_SRCS 3 3 dockicon.cpp 4 dockiconwidget.cpp5 4 systemtrayicon.cpp 6 5 ) … … 8 7 # Other dock icons not available with kde 9 8 if (NOT WITH_KDE) 10 list(APPEND dockicons_SRCS d efaultdockicon.cpp themeddockicon.cpp)9 list(APPEND dockicons_SRCS dockiconwidget.cpp defaultdockicon.cpp themeddockicon.cpp) 11 10 endif (NOT WITH_KDE) 12 11 -
branches/qt-gui_qt4/src/dockicons/defaultdockicon.cpp
r5837 r6058 48 48 49 49 DefaultDockIcon::DefaultDockIcon(QMenu* menu) 50 : DockIcon( menu)50 : DockIcon() 51 51 { 52 myIcon = new DockIconWidget(menu); 53 relayDockIconSignals(); 52 54 updateConfig(); 53 }54 55 DefaultDockIcon::~DefaultDockIcon()56 {57 delete pix;58 55 } 59 56 … … 62 59 myFortyEight = Config::General::instance()->defaultIconFortyEight(); 63 60 64 delete myIcon; 61 QPixmap* pic = new QPixmap(myFortyEight ? back48_xpm : back64_xpm); 62 QBitmap bmp = QBitmap(myFortyEight ? mask48_xpm : mask64_xpm); 63 pic->setMask(bmp); 64 myIcon->setFace(pic); 65 delete pic; 65 66 66 if (myFortyEight) 67 { 68 pix = new QPixmap(back48_xpm); 69 QBitmap b; 70 b = QPixmap(mask48_xpm); 71 pix->setMask(b); 72 myIcon = new DockIconWidget(pix, this); 73 } 74 else 75 { 76 pix = new QPixmap(back64_xpm); 77 QBitmap b; 78 b = QPixmap(mask64_xpm); 79 pix->setMask(b); 80 myIcon = new DockIconWidget(pix, this); 81 } 82 X11Init(); 67 updateStatusIcon(); 68 updateIconMessages(myNewMsg, mySysMsg); 83 69 } 84 70 … … 87 73 DockIcon::updateStatusIcon(); 88 74 75 if (!myFortyEight && myNewMsg == 0 && mySysMsg == 0) 76 drawIcon64(myStatusIcon); 77 89 78 QPixmap m; 90 switch (myStatus)91 {92 case ICQ_STATUS_ONLINE: m = QPixmap(online_xpm); break;93 case ICQ_STATUS_AWAY: m = QPixmap(away_xpm); break;94 case ICQ_STATUS_NA: m = QPixmap(na_xpm); break;95 case ICQ_STATUS_OCCUPIED: m = QPixmap(occupied_xpm); break;96 case ICQ_STATUS_DND: m = QPixmap(dnd_xpm); break;97 case ICQ_STATUS_FREEFORCHAT: m = QPixmap(ffc_xpm); break;98 case ICQ_STATUS_OFFLINE: m = QPixmap(offline_xpm); break;99 }100 79 if (myInvisible) 101 80 m = QPixmap(invisible_xpm); 81 else 82 switch (myStatus) 83 { 84 case ICQ_STATUS_ONLINE: m = QPixmap(online_xpm); break; 85 case ICQ_STATUS_AWAY: m = QPixmap(away_xpm); break; 86 case ICQ_STATUS_NA: m = QPixmap(na_xpm); break; 87 case ICQ_STATUS_OCCUPIED: m = QPixmap(occupied_xpm); break; 88 case ICQ_STATUS_DND: m = QPixmap(dnd_xpm); break; 89 case ICQ_STATUS_FREEFORCHAT: m = QPixmap(ffc_xpm); break; 90 case ICQ_STATUS_OFFLINE: m = QPixmap(offline_xpm); break; 91 } 102 92 103 QPainter painter(myIcon->vis); 104 if (!myFortyEight) 105 { 106 painter.drawPixmap(0, 44, m); 107 // Draw the little icon if no new messages 108 if (myNewMsg == 0 && mySysMsg == 0) 109 { 110 QPixmap* p = &myStatusIcon; 111 painter.fillRect(31, 6, 27, 16, QColor(0,0,0)); 112 if (p != NULL) 113 { 114 int w = p->width() > 27 ? 27 : p->width(); 115 int h = p->height() > 16 ? 16 : p->height(); 116 int x = 45 - (w / 2); 117 int y = 14 - (h / 2); 118 painter.drawPixmap(x, y, *p, 0, 0, w, h); 119 } 120 } 121 } 122 else 123 painter.drawPixmap(0, 27, m); 93 QPixmap* face = myIcon->face(); 94 QPainter painter(face); 95 painter.drawPixmap(0, myFortyEight ? 27 : 44, m); 124 96 painter.end(); 125 97 126 myIcon->repaint(); 127 repaint(); 128 } 129 130 void DefaultDockIcon::splitDigits(int num, int& low, int &high) 131 { 132 if (num > 99) 133 { 134 low = 9; 135 high = 9; 136 } 137 else 138 { 139 low = num % 10; 140 high = num / 10; 141 } 98 myIcon->setFace(face); 99 delete face; 142 100 } 143 101 144 102 void DefaultDockIcon::updateIconMessages(int newMsg, int sysMsg) 145 103 { 146 QPainter p(myIcon->vis); 147 int d1, d10; 104 DockIcon::updateIconMessages(newMsg, sysMsg); 148 105 149 // set the new msg digits 150 splitDigits(newMsg, d1, d10); 106 int low, high; 151 107 152 if (!myFortyEight) 153 { 154 p.drawPixmap(44, 26, digits[d10]); 155 p.drawPixmap(50, 26, digits[d1]); 156 } 157 else 158 { 159 p.drawPixmap(44, 9, digits[d10]); 160 p.drawPixmap(50, 9, digits[d1]); 161 } 108 #define SPLIT(num) \ 109 (num) = qMin(num, 99); \ 110 low = (num) % 10; \ 111 high = (num) / 10; 162 112 163 // set the system msg digits164 splitDigits(sysMsg, d1, d10);113 QPixmap* face = myIcon->face(); 114 QPainter p(face); 165 115 166 if (!myFortyEight) 167 { 168 p.drawPixmap(44, 38, digits[d10]); 169 p.drawPixmap(50, 38, digits[d1]); 170 } 171 else 172 { 173 p.drawPixmap(44, 21, digits[d10]); 174 p.drawPixmap(50, 21, digits[d1]); 175 } 116 SPLIT(newMsg); 117 p.drawPixmap(44, myFortyEight ? 8 : 26, digits[high]); 118 p.drawPixmap(50, myFortyEight ? 8 : 26, digits[low]); 119 120 SPLIT(sysMsg); 121 p.drawPixmap(44, myFortyEight ? 20 : 38, digits[high]); 122 p.drawPixmap(50, myFortyEight ? 20 : 38, digits[low]); 123 176 124 p.end(); 177 125 178 // Base class will trigger updateEventIcon to actually paint the icon179 DockIcon::updateIconMessages(newMsg, sysMsg);126 myIcon->setFace(face); 127 delete face; 180 128 } 181 129 182 130 void DefaultDockIcon::updateEventIcon() 183 131 { 184 if (!myFortyEight) 185 { 186 QPainter p(myIcon->vis); 132 DockIcon::updateEventIcon(); 187 133 188 // Draw the little icon now 189 QPixmap* m = NULL; 190 if (mySysMsg > 0 || myNewMsg > 0) 191 m = &myEventIcon; 192 else 193 m = &myStatusIcon; 194 p.fillRect(31, 6, 27, 16, QColor(0,0,0)); 195 if (m != NULL) 196 { 197 int w = m->width() > 27 ? 27 : m->width(); 198 int h = m->height() > 16 ? 16 : m->height(); 199 int x = 45 - (w / 2); 200 int y = 14 - (h / 2); 201 p.drawPixmap(x, y, *m, 0, 0, w, h); 202 } 134 if (myFortyEight) 135 return; 203 136 204 p.end();205 }137 drawIcon64((mySysMsg > 0 || myNewMsg > 0) ? myEventIcon : myStatusIcon); 138 } 206 139 207 myIcon->repaint(); 208 repaint(); 140 void DefaultDockIcon::drawIcon64(QPixmap* icon) 141 { 142 if (icon == NULL || icon->isNull()) 143 return; 144 145 QPixmap* face = myIcon->face(); 146 QPainter p(face); 147 148 // Clear the icon area 149 p.fillRect(31, 6, 27, 16, Qt::black); 150 151 // Calculate drawing coordinates 152 int w = qMin(icon->width(), 27); 153 int h = qMin(icon->height(), 16); 154 int x = 45 - (w / 2); 155 int y = 14 - (h / 2); 156 157 p.drawPixmap(x, y, *icon, 0, 0, w, h); 158 p.end(); 159 160 myIcon->setFace(face); 161 delete face; 209 162 } -
branches/qt-gui_qt4/src/dockicons/defaultdockicon.h
r5837 r6058 22 22 #define DEFAULTDOCKICON_H 23 23 24 class QMenu; 25 class QPixmap; 26 24 27 #include "dockicon.h" 25 28 … … 41 44 */ 42 45 DefaultDockIcon(QMenu* menu); 43 44 /**45 * Destructor46 */47 virtual ~DefaultDockIcon();48 46 49 47 /** … … 73 71 private: 74 72 /** 75 * Get the two lower digits from a number73 * Draws a given @a icon into the 64x64 dock icon area 76 74 * 77 * @param num Number to split 78 * @param low Return variable for lower digit 79 * @param high Return variable for second lowest digit 75 * @param icon The icon to draw 80 76 */ 81 void splitDigits(int num, int& low, int& high);77 void drawIcon64(QPixmap* icon); 82 78 83 QPixmap* pix;84 79 bool myFortyEight; 85 80 }; -
branches/qt-gui_qt4/src/dockicons/dockicon.cpp
r5990 r6058 23 23 #include "config.h" 24 24 25 #include <QBitmap>26 #include <QCloseEvent>27 #include <QMenu>28 #include <QMouseEvent>29 #include <QPainter>30 31 #ifdef Q_WS_X1132 #include <QX11Info>33 #include <X11/Xlib.h>34 #include <X11/Xutil.h>35 #undef Status36 #endif37 38 25 #include <licq_user.h> 39 26 … … 42 29 43 30 #include "helpers/licqstrings.h" 44 #include "helpers/support.h"45 31 46 32 #include "dockiconwidget.h" … … 49 35 /* TRANSLATOR LicqQtGui::DockIcon */ 50 36 51 DockIcon::DockIcon(QMenu* menu) 52 : QWidget(NULL), 53 myMenu(menu), 37 DockIcon::DockIcon() 38 : QObject(), 54 39 myIcon(NULL), 55 40 myNewMsg(0), … … 58 43 myInvisible(false) 59 44 { 60 Support::setWidgetProps(this, "Wharf");61 setWindowFlags(Qt::Window);62 setWindowTitle("LicqWharf");63 setBackgroundRole(QPalette::NoRole);64 65 45 // Get icon set updates 66 46 connect(IconManager::instance(), SIGNAL(statusIconsChanged()), SLOT(updateStatusIcon())); … … 69 49 // Get configuration updates 70 50 connect(Config::General::instance(), SIGNAL(dockChanged()), SLOT(updateConfig())); 51 52 unsigned short sysMsg = 0; 53 54 FOR_EACH_OWNER_START(LOCK_R) 55 { 56 sysMsg += pOwner->NewMessages(); 57 } 58 FOR_EACH_OWNER_END 59 60 unsigned short newMsg = ICQUser::getNumUserEvents() - sysMsg; 61 62 updateIconMessages(newMsg, sysMsg); 63 updateIconStatus(); 71 64 } 72 65 … … 74 67 { 75 68 delete myIcon; 76 }77 78 void DockIcon::X11Init()79 {80 // set the hints81 #if defined(Q_WS_X11) && !defined(USE_KDE)82 Display* dsp = x11Info().display(); // get the display83 WId win = winId(); // get the window84 85 XSizeHints sizeHints;86 sizeHints.flags = USPosition;87 sizeHints.x = 0;88 sizeHints.y = 0;89 XSetWMNormalHints(dsp, win, &sizeHints);90 91 XWMHints* hints = XAllocWMHints(); // hints92 hints->initial_state = WithdrawnState;93 hints->icon_x = 0;94 hints->icon_y = 0;95 hints->icon_window = myIcon->winId();96 hints->window_group = win; // set the window hint97 hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint; // set the window group hint98 XSetWMHints(dsp, win, hints); // set the window hints for WM to use.99 XFree(hints);100 101 XMapWindow(dsp, myIcon->winId());102 XMapWindow(dsp, win);103 XSync(dsp, False);104 105 #endif /* defined(Q_WS_X11) && !defined(USE_KDE) */106 107 resize(myIcon->size());108 setMask(myIcon->mask());109 move(-100, -100);110 updateToolTip();111 show();112 #if defined(Q_WS_X11) && !defined(USE_KDE)113 XWithdrawWindow(dsp, win, XScreenNumberOfScreen(DefaultScreenOfDisplay(dsp)));114 #endif /* defined(Q_WS_X11) && !defined(USE_KDE) */115 69 } 116 70 … … 124 78 { 125 79 OwnerList* ol = gUserManager.LockOwnerList(LOCK_R); 126 for (OwnerList::iterator i = ol->begin(); i != ol->end(); i++) 127 { 128 o = *i; 129 o->Lock(LOCK_R); 130 break; 131 } 80 o = ol->front(); 81 o->Lock(LOCK_R); 132 82 gUserManager.UnlockOwnerList(); 133 83 } … … 159 109 void DockIcon::updateStatusIcon() 160 110 { 161 myStatusIcon = IconManager::instance()->iconForStatus(myFullStatus, myId, myPpid); 111 myStatusIcon = const_cast<QPixmap*> 112 (&IconManager::instance()->iconForStatus(myFullStatus, myId, myPpid)); 162 113 } 163 114 … … 174 125 { 175 126 if (mySysMsg > 0) 176 myEventIcon = IconManager::instance()->getIcon(IconManager::ReqAuthorizeMessageIcon); 127 myEventIcon = const_cast<QPixmap*> 128 (&IconManager::instance()->getIcon(IconManager::ReqAuthorizeMessageIcon)); 177 129 else if (myNewMsg > 0) 178 myEventIcon = IconManager::instance()->getIcon(IconManager::StandardMessageIcon); 130 myEventIcon = const_cast<QPixmap*> 131 (&IconManager::instance()->getIcon(IconManager::StandardMessageIcon)); 179 132 else 180 myEventIcon = QPixmap();133 myEventIcon = NULL; 181 134 } 182 135 … … 201 154 myIcon->setToolTip(s); 202 155 else 203 setToolTip(s);156 emit newToolTip(s); 204 157 } 205 158 206 void DockIcon:: closeEvent(QCloseEvent* event)159 void DockIcon::relayDockIconSignals() 207 160 { 208 event->ignore(); 161 if (myIcon == NULL) 162 return; 163 164 connect(myIcon, SIGNAL(clicked()), SIGNAL(clicked())); 165 connect(myIcon, SIGNAL(middleClicked()), SIGNAL(middleClicked())); 209 166 } 210 211 void DockIcon::mousePressEvent(QMouseEvent* event)212 {213 switch (event->button())214 {215 case Qt::LeftButton:216 emit clicked();217 break;218 219 case Qt::MidButton:220 emit middleClicked();221 break;222 223 case Qt::RightButton:224 myMenu->popup(event->globalPos());225 break;226 227 default:228 break;229 }230 }231 232 void DockIcon::paintEvent(QPaintEvent* /* event */)233 {234 QPainter painter(this);235 myIcon->drawIcon(painter);236 painter.end();237 } -
branches/qt-gui_qt4/src/dockicons/dockicon.h
r5837 r6058 22 22 #define DOCKICON_H 23 23 24 #include <Q Widget>24 #include <QObject> 25 25 26 class Q Menu;26 class QPixmap; 27 27 28 28 class ICQOwner; … … 36 36 * Only holds state and common functions needed by dock icon implementations 37 37 */ 38 class DockIcon : public Q Widget38 class DockIcon : public QObject 39 39 { 40 40 Q_OBJECT … … 43 43 /** 44 44 * Constructor 45 *46 * @param menu System menu to popup from dock icon on right click47 45 */ 48 DockIcon( QMenu* menu);46 DockIcon(); 49 47 50 48 /** … … 79 77 void middleClicked(); 80 78 79 /** 80 * New tooltip is available 81 * Emitted when myIcon isn't set 82 */ 83 void newToolTip(QString tooltip); 84 81 85 protected slots: 82 86 /** … … 97 101 protected: 98 102 /** 99 * Setup X hints needed to mark icon window as dockable by some window managers100 */101 void X11Init();102 103 /**104 103 * Update tool tip text for dock icon 105 104 */ … … 107 106 108 107 /** 109 * User has clicked on icon 110 * 111 * @param event Event object 108 * Connects signals from myIcon onto this 112 109 */ 113 v irtual void mousePressEvent(QMouseEvent* event);110 void relayDockIconSignals(); 114 111 115 /**116 * User tried to close icon window117 *118 * @param event Event object119 */120 virtual void closeEvent(QCloseEvent* event);121 122 /**123 * Repaint icon window124 *125 * @param event Event object126 */127 virtual void paintEvent(QPaintEvent* event);128 129 QMenu* myMenu;130 112 DockIconWidget* myIcon; 131 113 int myNewMsg; … … 134 116 unsigned short myStatus; 135 117 bool myInvisible; 136 QPixmap myStatusIcon; 137 QPixmap myEventIcon; 138 139 friend class DockIconWidget; 118 QPixmap* myStatusIcon; 119 QPixmap* myEventIcon; 140 120 141 121 private: -
branches/qt-gui_qt4/src/dockicons/dockiconwidget.cpp
r5837 r6058 23 23 #include "config.h" 24 24 25 #include <QCloseEvent> 25 26 #include <QBitmap> 27 #include <QMenu> 26 28 #include <QPainter> 29 30 #include "helpers/support.h" 27 31 28 32 #include "dockicon.h" … … 30 34 using namespace LicqQtGui; 31 35 32 DockIconWidget::DockIconWidget(QPixmap* pix, DockIcon* parent) 33 : QWidget(parent), 34 vis(NULL) 36 DockIconWidget::DockIconWidget(QMenu* menu) 37 : QWidget(), 38 myMenu(menu), 39 myFace(NULL) 35 40 { 36 setObjectName("DockIconWidget"); 37 Set(pix); 38 } 39 40 void DockIconWidget::Set(QPixmap* pix) 41 { 42 delete vis; 43 vis = new QPixmap(*pix); 44 resize(vis->size()); 45 setMask(vis->mask()); 46 repaint(); 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 47 } 48 48 49 49 DockIconWidget::~DockIconWidget() 50 50 { 51 delete vis; 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(); 52 79 } 53 80 54 81 void DockIconWidget::mousePressEvent(QMouseEvent* event) 55 82 { 56 dynamic_cast<DockIcon*>(parent())->mousePressEvent(event); 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 } 57 100 } 58 101 59 void DockIconWidget:: drawIcon(QPainter& painter)102 void DockIconWidget::paintEvent(QPaintEvent* event) 60 103 { 61 if ( !vis)104 if (myFace == NULL) 62 105 return; 63 painter.drawPixmap(0, 0, *vis); 106 107 event->ignore(); 108 QPainter painter(this); 109 painter.drawPixmap(0, 0, *myFace); 64 110 } 65 66 void DockIconWidget::paintEvent(QPaintEvent* /* event */)67 {68 QPainter painter(this);69 drawIcon(painter);70 painter.end();71 } -
branches/qt-gui_qt4/src/dockicons/dockiconwidget.h
r5837 r6058 24 24 #include <QWidget> 25 25 26 class QMenu; 27 26 28 namespace LicqQtGui 27 29 { 28 class DockIcon;29 30 30 /**
