Commit 7c8c38bda762d72f067700026b0c863a8e50e59b
- Diff rendering mode:
- inline
- side by side
src/quax.cpp
(146 / 191)
|   | |||
| 54 | 54 | #include <QDesktopWidget> | |
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | Quax::Quax() : QWidget(0,0,Qt::WStyle_Customize|Qt::WStyle_NoBorder|Qt::WType_TopLevel) { | ||
| 57 | Quax::Quax() | ||
| 58 | : QWidget(0,0,Qt::WStyle_Customize|Qt::WStyle_NoBorder|Qt::WType_TopLevel) | ||
| 59 | , m_colorStringDecimal("255, 255, 255") | ||
| 60 | , m_colorStringHexaLower("#ffffff") | ||
| 61 | , m_colorStringHexaUpper("#FFFFFF") | ||
| 62 | , m_pixelColorIcon(new QIcon) | ||
| 63 | , m_inDrag(false) | ||
| 64 | , m_colorTipShowed(false) | ||
| 65 | , m_cursorOverQuax(false) | ||
| 66 | , m_ctrlKeyOn(false) | ||
| 67 | , m_zoom(ZOOM_SCALE_MIN) | ||
| 68 | , m_lookAt(0) | ||
| 69 | { | ||
| 70 | // customize looks | ||
| 71 | //setAttribute(Qt::WA_NoSystemBackground); | ||
| 72 | setFixedSize(150, 150); | ||
| 73 | setCursor(Qt::PointingHandCursor); | ||
| 74 | setIcon(QPixmap(icon_xpm)); | ||
| 58 | 75 | ||
| 59 | QPixmap icon=QPixmap(icon_xpm); | ||
| 60 | setIcon(icon); | ||
| 76 | // set the background image and shape | ||
| 77 | pix = QPixmap(mag_xpm); | ||
| 78 | QPalette pal; | ||
| 79 | pal.setBrush(QPalette::Window, pix); | ||
| 80 | setAutoFillBackground(true); | ||
| 81 | setPalette(pal); | ||
| 82 | pix_alpha = QPixmap(mag_alpha_xpm); | ||
| 83 | setMask(pix_alpha.mask()); | ||
| 61 | 84 | ||
| 62 | #ifdef _OS_WIN32_ | ||
| 63 | hand_cursor = QCursor(Qt::ArrowCursor); | ||
| 64 | #else | ||
| 65 | // "borrowed" from kcursor.cpp from kdelibs | ||
| 66 | static const unsigned char HAND_BITS[] = { | ||
| 67 | 0x80, 0x01, 0x00, 0x40, 0x02, 0x00, 0x40, 0x02, 0x00, 0x40, 0x02, | ||
| 68 | 0x00, 0x40, 0x02, 0x00, 0x40, 0x02, 0x00, 0x40, 0x1e, 0x00, 0x40, | ||
| 69 | 0xf2, 0x00, 0x40, 0x92, 0x01, 0x70, 0x92, 0x02, 0x50, 0x92, 0x04, | ||
| 70 | 0x48, 0x80, 0x04, 0x48, 0x00, 0x04, 0x48, 0x00, 0x04, 0x08, 0x00, | ||
| 71 | 0x04, 0x08, 0x00, 0x04, 0x10, 0x00, 0x04, 0x10, 0x00, 0x04, 0x20, | ||
| 72 | 0x00, 0x02, 0x40, 0x00, 0x02, 0x40, 0x00, 0x01, 0xc0, 0xff, 0x01 | ||
| 73 | }; | ||
| 74 | static const unsigned char HAND_MASK_BITS[] = { | ||
| 75 | 0x80, 0x01, 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x03, | ||
| 76 | 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x1f, 0x00, 0xc0, | ||
| 77 | 0xff, 0x00, 0xc0, 0xff, 0x01, 0xf0, 0xff, 0x03, 0xf0, 0xff, 0x07, | ||
| 78 | 0xf8, 0xff, 0x07, 0xf8, 0xff, 0x07, 0xf8, 0xff, 0x07, 0xf8, 0xff, | ||
| 79 | 0x07, 0xf8, 0xff, 0x07, 0xf0, 0xff, 0x07, 0xf0, 0xff, 0x07, 0xe0, | ||
| 80 | 0xff, 0x03, 0xc0, 0xff, 0x03, 0xc0, 0xff, 0x01, 0xc0, 0xff, 0x01 | ||
| 81 | }; | ||
| 82 | QBitmap hand_bitmap(22, 22, HAND_BITS, true); | ||
| 83 | QBitmap hand_mask(22, 22, HAND_MASK_BITS, true); | ||
| 84 | hand_cursor = QCursor(hand_bitmap, hand_mask, 7, 0); | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #if QT_VERSION >= 300 | ||
| 88 | cross_cursor = QCursor(Qt::CrossCursor); | ||
| 89 | copy_cursor = QCursor(Qt::SizeAllCursor); | ||
| 90 | #else | ||
| 91 | |||
| 92 | cross_cursor = QCursor(CrossCursor); | ||
| 93 | copy_cursor = QCursor(SizeAllCursor); | ||
| 94 | #endif | ||
| 95 | setCursor(hand_cursor); | ||
| 96 | |||
| 97 | // fix the size | ||
| 98 | setMinimumHeight(150); | ||
| 99 | setMaximumHeight(150); | ||
| 100 | setMinimumWidth(150); | ||
| 101 | setMaximumWidth(150); | ||
| 102 | /// setBackgroundMode(NoBackground); | ||
| 103 | |||
| 104 | // set the shape | ||
| 105 | pix=QPixmap(mag_xpm); | ||
| 106 | pix_alpha=QPixmap(mag_alpha_xpm); | ||
| 107 | /// setMask(*pix_alpha.mask()); | ||
| 108 | #if QT_VERSION > 300 | ||
| 109 | setErasePixmap(pix); | ||
| 110 | #else | ||
| 111 | setBackgroundPixmap(pix); | ||
| 112 | #endif | ||
| 113 | |||
| 114 | |||
| 115 | 85 | pix_cursor.resize(14,14); | |
| 116 | pixelColorIcon = new QIcon(); | ||
| 117 | colorStringDecimal = QString("255, 255, 255"); | ||
| 118 | colorStringHexaLower = QString("#ffffff"); | ||
| 119 | colorStringHexaUpper = QString("#FFFFFF"); | ||
| 120 | 86 | ||
| 121 | colorTipShowed=false; | ||
| 122 | cursorOverQuax=false; | ||
| 123 | ctrlKeyOn=false; | ||
| 124 | zoom=ZOOM_SCALE_MIN; | ||
| 125 | inDrag=0; | ||
| 126 | look=0; | ||
| 127 | |||
| 128 | |||
| 129 | 87 | // build RMB popup menu | |
| 130 | 88 | menu = new QMenu(this); | |
| 131 | |||
| 132 | menuzoom = new QMenu(this); | ||
| 133 | menuzoom->setCheckable(true); | ||
| 134 | for (int i=ZOOM_SCALE_MIN; i<=ZOOM_SCALE_MAX; i++) { | ||
| 135 | zoomid[i]=menuzoom->insertItem(QObject::tr("1:%1").arg(i),this,SLOT(zoomTo(int))); | ||
| 136 | } | ||
| 137 | menuzoom->insertSeparator(); | ||
| 89 | menuZoom = new QMenu(this); | ||
| 90 | menuZoom->setCheckable(true); | ||
| 91 | for (int i = ZOOM_SCALE_MIN; i <= ZOOM_SCALE_MAX; i++) | ||
| 92 | zoomid[i]=menuZoom->insertItem(tr("1:%1").arg(i), this, SLOT(zoomTo(int))); | ||
| 93 | menuZoom->addSeparator(); | ||
| 138 | 94 | #if QT_VERSION >= 300 | |
| 139 | menuzoom->insertItem(QPixmap(viewmagin_xpm),QObject::tr("Zoom In"),this,SLOT(zoomIn()),QKeySequence(QObject::tr("+","Zoom In"))); | ||
| 140 | menuzoom->insertItem(QPixmap(viewmagout_xpm),QObject::tr("Zoom Out"),this,SLOT(zoomOut()),QKeySequence(QObject::tr("-","Zoom Out"))); | ||
| 95 | menuZoom->insertItem(QPixmap(viewmagin_xpm),QObject::tr("Zoom In"),this,SLOT(zoomIn()),QKeySequence(QObject::tr("+","Zoom In"))); | ||
| 96 | menuZoom->insertItem(QPixmap(viewmagout_xpm),QObject::tr("Zoom Out"),this,SLOT(zoomOut()),QKeySequence(QObject::tr("-","Zoom Out"))); | ||
| 141 | 97 | #else | |
| 142 | menuzoom->insertItem(QPixmap(viewmagin_xpm),QObject::tr("Zoom In"),this,SLOT(zoomIn()),Q3Accel::stringToKey(QObject::tr("+","Zoom In"))); | ||
| 143 | menuzoom->insertItem(QPixmap(viewmagout_xpm),QObject::tr("Zoom Out"),this,SLOT(zoomOut()),Q3Accel::stringToKey(QObject::tr("-","Zoom Out"))); | ||
| 98 | menuZoom->insertItem(QPixmap(viewmagin_xpm),QObject::tr("Zoom In"),this,SLOT(zoomIn()),Q3Accel::stringToKey(QObject::tr("+","Zoom In"))); | ||
| 99 | menuZoom->insertItem(QPixmap(viewmagout_xpm),QObject::tr("Zoom Out"),this,SLOT(zoomOut()),Q3Accel::stringToKey(QObject::tr("-","Zoom Out"))); | ||
| 144 | 100 | #endif | |
| 145 | 101 | ||
| 146 | menulook = new QMenu(this); | ||
| 147 | menulook->setCheckable(true); | ||
| 102 | menuLook = new QMenu(this); | ||
| 103 | menuLook->setCheckable(true); | ||
| 148 | 104 | #if QT_VERSION >= 300 | |
| 149 | lookid[1]=menulook->insertItem(QObject::tr("North-West"),this,SLOT(rotateNorthWest()),QKeySequence(QObject::tr("U","North-West"))); | ||
| 150 | lookid[0]=menulook->insertItem(QObject::tr("South-West"),this,SLOT(rotateSouthWest()),QKeySequence(QObject::tr("J","South-West"))); | ||
| 151 | lookid[2]=menulook->insertItem(QObject::tr("North-East"),this,SLOT(rotateNorthEast()),QKeySequence(QObject::tr("I","North-East"))); | ||
| 152 | lookid[3]=menulook->insertItem(QObject::tr("South-East"),this,SLOT(rotateSouthEast()),QKeySequence(QObject::tr("K","South-East"))); | ||
| 105 | lookid[1]=menuLook->insertItem(QObject::tr("North-West"),this,SLOT(rotateNorthWest()),QKeySequence(QObject::tr("U","North-West"))); | ||
| 106 | lookid[0]=menuLook->insertItem(QObject::tr("South-West"),this,SLOT(rotateSouthWest()),QKeySequence(QObject::tr("J","South-West"))); | ||
| 107 | lookid[2]=menuLook->insertItem(QObject::tr("North-East"),this,SLOT(rotateNorthEast()),QKeySequence(QObject::tr("I","North-East"))); | ||
| 108 | lookid[3]=menuLook->insertItem(QObject::tr("South-East"),this,SLOT(rotateSouthEast()),QKeySequence(QObject::tr("K","South-East"))); | ||
| 153 | 109 | #else | |
| 154 | lookid[1]=menulook->insertItem(QObject::tr("North-West"),this,SLOT(rotateNorthWest()),Q3Accel::stringToKey(QObject::tr("u","North-West"))); | ||
| 155 | lookid[0]=menulook->insertItem(QObject::tr("South-West"),this,SLOT(rotateSouthWest()),Q3Accel::stringToKey(QObject::tr("j","South-West"))); | ||
| 156 | lookid[2]=menulook->insertItem(QObject::tr("North-East"),this,SLOT(rotateNorthEast()),Q3Accel::stringToKey(QObject::tr("i","North-East"))); | ||
| 157 | lookid[3]=menulook->insertItem(QObject::tr("South-East"),this,SLOT(rotateSouthEast()),Q3Accel::stringToKey(QObject::tr("k","South-East"))); | ||
| 110 | lookid[1]=menuLook->insertItem(QObject::tr("North-West"),this,SLOT(rotateNorthWest()),Q3Accel::stringToKey(QObject::tr("u","North-West"))); | ||
| 111 | lookid[0]=menuLook->insertItem(QObject::tr("South-West"),this,SLOT(rotateSouthWest()),Q3Accel::stringToKey(QObject::tr("j","South-West"))); | ||
| 112 | lookid[2]=menuLook->insertItem(QObject::tr("North-East"),this,SLOT(rotateNorthEast()),Q3Accel::stringToKey(QObject::tr("i","North-East"))); | ||
| 113 | lookid[3]=menuLook->insertItem(QObject::tr("South-East"),this,SLOT(rotateSouthEast()),Q3Accel::stringToKey(QObject::tr("k","South-East"))); | ||
| 158 | 114 | #endif | |
| 159 | menulook->insertSeparator(); | ||
| 115 | menuLook->insertSeparator(); | ||
| 160 | 116 | #if QT_VERSION >= 300 | |
| 161 | menulook->insertItem(QPixmap(left_xpm),QObject::tr("Rotate Left"),this,SLOT(rotateLeft()),QKeySequence(QObject::tr("L","Rotate Left"))); | ||
| 162 | menulook->insertItem(QPixmap(right_xpm),QObject::tr("Rotate Right"),this,SLOT(rotateRight()),QKeySequence(QObject::tr("R","Rotate Right"))); | ||
| 117 | menuLook->insertItem(QPixmap(left_xpm),QObject::tr("Rotate Left"),this,SLOT(rotateLeft()),QKeySequence(QObject::tr("L","Rotate Left"))); | ||
| 118 | menuLook->insertItem(QPixmap(right_xpm),QObject::tr("Rotate Right"),this,SLOT(rotateRight()),QKeySequence(QObject::tr("R","Rotate Right"))); | ||
| 163 | 119 | #else | |
| 164 | menulook->insertItem(QPixmap(left_xpm),QObject::tr("Rotate Left"),this,SLOT(rotateLeft()),Q3Accel::stringToKey(QObject::tr("l","Rotate Left"))); | ||
| 165 | menulook->insertItem(QPixmap(right_xpm),QObject::tr("Rotate Right"),this,SLOT(rotateRight()),Q3Accel::stringToKey(QObject::tr("r","Rotate Right"))); | ||
| 120 | menuLook->insertItem(QPixmap(left_xpm),QObject::tr("Rotate Left"),this,SLOT(rotateLeft()),Q3Accel::stringToKey(QObject::tr("l","Rotate Left"))); | ||
| 121 | menuLook->insertItem(QPixmap(right_xpm),QObject::tr("Rotate Right"),this,SLOT(rotateRight()),Q3Accel::stringToKey(QObject::tr("r","Rotate Right"))); | ||
| 166 | 122 | #endif | |
| 167 | 123 | ||
| 168 | menucolor = new QMenu(this); | ||
| 169 | colorid[1]=menucolor->insertItem(colorStringDecimal,this,SLOT(copyColor(int))); | ||
| 124 | menuColor = new QMenu(this); | ||
| 125 | colorid[1]=menuColor->insertItem(m_colorStringDecimal,this,SLOT(copyColor(int))); | ||
| 170 | 126 | #if QT_VERSION >= 300 | |
| 171 | colorid[2]=menucolor->insertItem(colorStringHexaLower,this,SLOT(copyColor(int)),QKeySequence(QObject::tr("Ctrl+C","Copy Color"))); | ||
| 127 | colorid[2]=menuColor->insertItem(m_colorStringHexaLower,this,SLOT(copyColor(int)),QKeySequence(QObject::tr("Ctrl+C","Copy Color"))); | ||
| 172 | 128 | #else | |
| 173 | colorid[2]=menucolor->insertItem(colorStringHexaLower,this,SLOT(copyColor(int)),Q3Accel::stringToKey(QObject::tr("Ctrl+c","Copy Color"))); | ||
| 129 | colorid[2]=menuColor->insertItem(m_colorStringHexaLower,this,SLOT(copyColor(int)),Q3Accel::stringToKey(QObject::tr("Ctrl+c","Copy Color"))); | ||
| 174 | 130 | #endif | |
| 175 | colorid[3]=menucolor->insertItem(colorStringHexaUpper,this,SLOT(copyColor(int))); | ||
| 131 | colorid[3]=menuColor->insertItem(m_colorStringHexaUpper,this,SLOT(copyColor(int))); | ||
| 176 | 132 | ||
| 177 | menu->insertItem(QPixmap(viewmag_xpm),QObject::tr("Zoom"),menuzoom); | ||
| 178 | menu->insertItem(QPixmap(look_xpm),QObject::tr("Look At"),menulook); | ||
| 179 | colorid[0]=menu->insertItem(pix_cursor,QObject::tr("Copy Color"),menucolor); | ||
| 133 | menu->insertItem(QPixmap(viewmag_xpm),QObject::tr("Zoom"),menuZoom); | ||
| 134 | menu->insertItem(QPixmap(look_xpm),QObject::tr("m_lookAt At"),menuLook); | ||
| 135 | colorid[0]=menu->insertItem(pix_cursor,QObject::tr("Copy Color"),menuColor); | ||
| 180 | 136 | #if QT_VERSION >= 300 | |
| 181 | 137 | menu->insertItem(QPixmap(help_xpm),QObject::tr("Help"),this,SLOT(help()),QKeySequence(QObject::tr("H","Help"))); | |
| 182 | 138 | #else | |
| … | … | ||
| 148 | 148 | menu->insertItem(QPixmap(exit_xpm),QObject::tr("Quit"),qApp,SLOT(quit()),Q3Accel::stringToKey(QObject::tr("q","Quit"))); | |
| 149 | 149 | #endif | |
| 150 | 150 | ||
| 151 | menuzoom->setItemChecked(zoomid[zoom],true); | ||
| 152 | menulook->setItemChecked(lookid[look],true); | ||
| 153 | connect(menu,SIGNAL(aboutToShow()),this,SLOT(updateMenuColor())); | ||
| 151 | menuZoom->setItemChecked(zoomid[m_zoom],true); | ||
| 152 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 153 | connect(menu,SIGNAL(aboutToShow()),this,SLOT(updatemenuColor())); | ||
| 154 | 154 | ||
| 155 | 155 | // set the color tooltip | |
| 156 | 156 | colorTip = new QLabel; /// (0,0,WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM); | |
| … | … | ||
| 165 | 165 | #endif | |
| 166 | 166 | /// colorTip->setAutoResize(true); | |
| 167 | 167 | colorTip->setFrameStyle(Q3Frame::Box | Q3Frame::Plain); | |
| 168 | colorTip->setPalette(QToolTip::palette()); | ||
| 169 | 168 | colorTip->setTextFormat(Qt::RichText); | |
| 170 | 169 | ||
| 171 | 170 | ||
| … | … | ||
| 181 | 181 | void Quax::enterEvent(QEvent *e) { | |
| 182 | 182 | e=e; | |
| 183 | 183 | ||
| 184 | cursorOverQuax=true; | ||
| 185 | if (colorTipShowed && colorTip->isHidden()) { | ||
| 184 | m_cursorOverQuax=true; | ||
| 185 | if (m_colorTipShowed && colorTip->isHidden()) { | ||
| 186 | 186 | displayColorTip(); | |
| 187 | 187 | } | |
| 188 | 188 | } | |
| … | … | ||
| 191 | 191 | void Quax::leaveEvent(QEvent *e) { | |
| 192 | 192 | e=e; | |
| 193 | 193 | ||
| 194 | cursorOverQuax=false; | ||
| 195 | if (colorTipShowed) { | ||
| 194 | m_cursorOverQuax=false; | ||
| 195 | if (m_colorTipShowed) { | ||
| 196 | 196 | colorTip->hide(); | |
| 197 | 197 | } | |
| 198 | 198 | } | |
| … | … | ||
| 232 | 232 | } | |
| 233 | 233 | ||
| 234 | 234 | void Quax::wheelEvent(QWheelEvent *e) { | |
| 235 | if (ctrlKeyOn) { | ||
| 235 | if (m_ctrlKeyOn) { | ||
| 236 | 236 | if (e->delta()>0) { | |
| 237 | 237 | rotateLeft(); | |
| 238 | 238 | } else { | |
| … | … | ||
| 246 | 246 | } | |
| 247 | 247 | } | |
| 248 | 248 | e->accept(); | |
| 249 | if (colorTipShowed && ! colorTip->isHidden()) { | ||
| 249 | if (m_colorTipShowed && ! colorTip->isHidden()) { | ||
| 250 | 250 | displayColorTip(); | |
| 251 | 251 | } | |
| 252 | 252 | } | |
| … | … | ||
| 256 | 256 | int x, y, w, h; | |
| 257 | 257 | int grabX, grabY, grabW, grabH, ofsX, ofsY; | |
| 258 | 258 | ||
| 259 | w = SHAPE_INNER_WIDTH/zoom; | ||
| 260 | h = SHAPE_INNER_HEIGHT/zoom; | ||
| 261 | switch (look) { | ||
| 259 | w = SHAPE_INNER_WIDTH/m_zoom; | ||
| 260 | h = SHAPE_INNER_HEIGHT/m_zoom; | ||
| 261 | switch (m_lookAt) { | ||
| 262 | 262 | case 0: // South-West | |
| 263 | 263 | x=this->x()-w; | |
| 264 | 264 | y=this->y()+height(); | |
| … | … | ||
| 278 | 278 | default: | |
| 279 | 279 | x=this->x(); | |
| 280 | 280 | y=this->y(); | |
| 281 | qWarning("look=%d: This must not happen",look); | ||
| 281 | qWarning("m_lookAt=%d: This must not happen",m_lookAt); | ||
| 282 | 282 | } | |
| 283 | 283 | ||
| 284 | 284 | // calculate grab surface to avoid garbage | |
| … | … | ||
| 320 | 320 | p.end(); | |
| 321 | 321 | ||
| 322 | 322 | QMatrix m; | |
| 323 | m.scale((double)zoom,(double)zoom); | ||
| 323 | m.scale((double)m_zoom,(double)m_zoom); | ||
| 324 | 324 | pix_zoom=pix_grab.xForm(m); | |
| 325 | 325 | repaint(false); | |
| 326 | 326 | } | |
| … | … | ||
| 330 | 330 | QPixmap pix_grab = QPixmap::grabWindow(QApplication::desktop()->winId(),QCursor::pos().x()-1,QCursor::pos().y()-1,1,1); | |
| 331 | 331 | QImage img_grab = pix_grab.convertToImage(); | |
| 332 | 332 | QRgb rgb_color = img_grab.pixel(0,0); | |
| 333 | colorStringDecimal = QString::number(qRed(rgb_color)) + ", " + | ||
| 333 | m_colorStringDecimal = QString::number(qRed(rgb_color)) + ", " + | ||
| 334 | 334 | QString::number(qGreen(rgb_color)) + ", " + | |
| 335 | 335 | QString::number(qBlue(rgb_color)); | |
| 336 | colorStringHexaLower.sprintf("#%02x%02x%02x",qRed(rgb_color),qGreen(rgb_color),qBlue(rgb_color)); | ||
| 337 | colorStringHexaUpper = colorStringHexaLower.upper(); | ||
| 336 | m_colorStringHexaLower.sprintf("#%02x%02x%02x",qRed(rgb_color),qGreen(rgb_color),qBlue(rgb_color)); | ||
| 337 | m_colorStringHexaUpper = m_colorStringHexaLower.upper(); | ||
| 338 | 338 | ||
| 339 | 339 | // make a little pixmap with grabbed color | |
| 340 | 340 | QMatrix m; | |
| … | … | ||
| 347 | 347 | /* | |
| 348 | 348 | grabForPixel(); | |
| 349 | 349 | Q3MimeSourceFactory::defaultFactory()->setPixmap("pixel",pix_cursor); | |
| 350 | colorTip->setText("<qml> <img height=\"14\" width=\"14\" src=\"pixel\"> <tt>" + colorStringHexaUpper + "</tt></qml>"); | ||
| 350 | colorTip->setText("<qml> <img height=\"14\" width=\"14\" src=\"pixel\"> <tt>" + m_colorStringHexaUpper + "</tt></qml>"); | ||
| 351 | 351 | ||
| 352 | 352 | int x_pos, y_pos; | |
| 353 | 353 | int x_ofs=7, y_ofs=5; | |
| … | … | ||
| 374 | 374 | void Quax::mousePressEvent(QMouseEvent *e) { | |
| 375 | 375 | switch (e->button()) { | |
| 376 | 376 | case Qt::LeftButton: | |
| 377 | if (colorTipShowed) { | ||
| 377 | if (m_colorTipShowed) { | ||
| 378 | 378 | copyColor(0); | |
| 379 | setCursor(copy_cursor); | ||
| 379 | setCursor(Qt::SizeAllCursor); | ||
| 380 | 380 | } else { | |
| 381 | grabMouse(hand_cursor); | ||
| 382 | inDrag=true; | ||
| 381 | grabMouse(Qt::PointingHandCursor); | ||
| 382 | m_inDrag=true; | ||
| 383 | 383 | dragOffset = QCursor::pos() - QPoint(geometry().left(),geometry().top()); | |
| 384 | 384 | } | |
| 385 | 385 | break; | |
| … | … | ||
| 394 | 394 | void Quax::mouseReleaseEvent(QMouseEvent *e) { | |
| 395 | 395 | switch (e->button()) { | |
| 396 | 396 | case Qt::LeftButton: | |
| 397 | if (colorTipShowed) { | ||
| 398 | setCursor(cross_cursor); | ||
| 397 | if (m_colorTipShowed) { | ||
| 398 | setCursor(Qt::CrossCursor); | ||
| 399 | 399 | } else { | |
| 400 | 400 | releaseMouse(); | |
| 401 | inDrag=false; | ||
| 401 | m_inDrag=false; | ||
| 402 | 402 | } | |
| 403 | 403 | break; | |
| 404 | 404 | default: | |
| … | … | ||
| 409 | 409 | void Quax::mouseMoveEvent(QMouseEvent *e) { | |
| 410 | 410 | e=e; | |
| 411 | 411 | ||
| 412 | if (colorTipShowed && cursorOverQuax) { | ||
| 412 | if (m_colorTipShowed && m_cursorOverQuax) { | ||
| 413 | 413 | displayColorTip(); | |
| 414 | 414 | } | |
| 415 | if (!inDrag || this != mouseGrabber()) return; | ||
| 415 | if (!m_inDrag || this != mouseGrabber()) return; | ||
| 416 | 416 | move(QCursor::pos()-dragOffset); | |
| 417 | 417 | } | |
| 418 | 418 | ||
| 419 | 419 | ||
| 420 | 420 | void Quax::keyReleaseEvent(QKeyEvent *e) { | |
| 421 | if (ctrlKeyOn) { | ||
| 421 | if (m_ctrlKeyOn) { | ||
| 422 | 422 | if (!(e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control)) { | |
| 423 | ctrlKeyOn=false; | ||
| 423 | m_ctrlKeyOn=false; | ||
| 424 | 424 | } | |
| 425 | 425 | } | |
| 426 | 426 | ||
| 427 | if (colorTipShowed) { | ||
| 427 | if (m_colorTipShowed) { | ||
| 428 | 428 | if (e->key() == Qt::Key_Control ||e->key() == Qt::Key_Shift) { | |
| 429 | colorTipShowed=false; | ||
| 430 | setCursor(hand_cursor); | ||
| 429 | m_colorTipShowed=false; | ||
| 430 | setCursor(Qt::PointingHandCursor); | ||
| 431 | 431 | colorTip->hide(); | |
| 432 | 432 | } | |
| 433 | 433 | } | |
| … | … | ||
| 437 | 437 | QPoint dist(0,0); | |
| 438 | 438 | ||
| 439 | 439 | if (!(e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control)) { | |
| 440 | ctrlKeyOn=true; | ||
| 440 | m_ctrlKeyOn=true; | ||
| 441 | 441 | e->ignore(); | |
| 442 | 442 | return; | |
| 443 | 443 | } | |
| 444 | 444 | ||
| 445 | if (!colorTipShowed) { | ||
| 445 | if (!m_colorTipShowed) { | ||
| 446 | 446 | if (((e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control)) || | |
| 447 | 447 | ((e->state() & Qt::ControlButton) && (e->key() == Qt::Key_Shift))) { | |
| 448 | colorTipShowed=true; | ||
| 449 | ctrlKeyOn=false; | ||
| 450 | setCursor(cross_cursor); | ||
| 448 | m_colorTipShowed=true; | ||
| 449 | m_ctrlKeyOn=false; | ||
| 450 | setCursor(Qt::CrossCursor); | ||
| 451 | 451 | displayColorTip(); | |
| 452 | 452 | e->ignore(); | |
| 453 | 453 | return; | |
| … | … | ||
| 526 | 526 | } | |
| 527 | 527 | ||
| 528 | 528 | void Quax::zoomIn() { | |
| 529 | if (zoom < ZOOM_SCALE_MAX) { | ||
| 530 | menuzoom->setItemChecked(zoomid[zoom],false); | ||
| 531 | zoom++; | ||
| 532 | menuzoom->setItemChecked(zoomid[zoom],true); | ||
| 529 | if (m_zoom < ZOOM_SCALE_MAX) { | ||
| 530 | menuZoom->setItemChecked(zoomid[m_zoom],false); | ||
| 531 | m_zoom++; | ||
| 532 | menuZoom->setItemChecked(zoomid[m_zoom],true); | ||
| 533 | 533 | } | |
| 534 | 534 | } | |
| 535 | 535 | ||
| 536 | 536 | void Quax::zoomOut() { | |
| 537 | if (zoom > ZOOM_SCALE_MIN) { | ||
| 538 | menuzoom->setItemChecked(zoomid[zoom],false); | ||
| 539 | zoom--; | ||
| 540 | menuzoom->setItemChecked(zoomid[zoom],true); | ||
| 537 | if (m_zoom > ZOOM_SCALE_MIN) { | ||
| 538 | menuZoom->setItemChecked(zoomid[m_zoom],false); | ||
| 539 | m_zoom--; | ||
| 540 | menuZoom->setItemChecked(zoomid[m_zoom],true); | ||
| 541 | 541 | } | |
| 542 | 542 | } | |
| 543 | 543 | ||
| 544 | 544 | void Quax::zoomTo(int pos) { | |
| 545 | for (int i=ZOOM_SCALE_MIN;i<=ZOOM_SCALE_MAX;i++) | ||
| 545 | for (int i = ZOOM_SCALE_MIN; i <= ZOOM_SCALE_MAX; i++) | ||
| 546 | 546 | if (zoomid[i]==pos) { | |
| 547 | menuzoom->setItemChecked(zoomid[i],true); | ||
| 548 | zoom=i; | ||
| 549 | } else { | ||
| 550 | menuzoom->setItemChecked(zoomid[i],false); | ||
| 551 | } | ||
| 547 | menuZoom->setItemChecked(zoomid[i],true); | ||
| 548 | m_zoom=i; | ||
| 549 | } else { | ||
| 550 | menuZoom->setItemChecked(zoomid[i],false); | ||
| 551 | } | ||
| 552 | 552 | } | |
| 553 | 553 | ||
| 554 | 554 | void Quax::rotateNorthWest() { | |
| 555 | menulook->setItemChecked(lookid[look],false); | ||
| 556 | look=1; | ||
| 557 | menulook->setItemChecked(lookid[look],true); | ||
| 558 | rotate(look); | ||
| 555 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 556 | m_lookAt=1; | ||
| 557 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 558 | rotate(m_lookAt); | ||
| 559 | 559 | } | |
| 560 | 560 | ||
| 561 | 561 | void Quax::rotateSouthWest() { | |
| 562 | menulook->setItemChecked(lookid[look],false); | ||
| 563 | look=0; | ||
| 564 | menulook->setItemChecked(lookid[look],true); | ||
| 565 | rotate(look); | ||
| 562 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 563 | m_lookAt=0; | ||
| 564 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 565 | rotate(m_lookAt); | ||
| 566 | 566 | } | |
| 567 | 567 | ||
| 568 | 568 | void Quax::rotateNorthEast() { | |
| 569 | menulook->setItemChecked(lookid[look],false); | ||
| 570 | look=2; | ||
| 571 | menulook->setItemChecked(lookid[look],true); | ||
| 572 | rotate(look); | ||
| 569 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 570 | m_lookAt=2; | ||
| 571 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 572 | rotate(m_lookAt); | ||
| 573 | 573 | } | |
| 574 | 574 | ||
| 575 | 575 | void Quax::rotateSouthEast() { | |
| 576 | menulook->setItemChecked(lookid[look],false); | ||
| 577 | look=3; | ||
| 578 | menulook->setItemChecked(lookid[look],true); | ||
| 579 | rotate(look); | ||
| 576 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 577 | m_lookAt=3; | ||
| 578 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 579 | rotate(m_lookAt); | ||
| 580 | 580 | } | |
| 581 | 581 | ||
| 582 | 582 | void Quax::rotateLeft() { | |
| 583 | menulook->setItemChecked(lookid[look],false); | ||
| 584 | if (look==0) { | ||
| 585 | look=3; | ||
| 583 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 584 | if (m_lookAt==0) { | ||
| 585 | m_lookAt=3; | ||
| 586 | 586 | } else { | |
| 587 | look--; | ||
| 587 | m_lookAt--; | ||
| 588 | 588 | } | |
| 589 | menulook->setItemChecked(lookid[look],true); | ||
| 590 | rotate(look); | ||
| 589 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 590 | rotate(m_lookAt); | ||
| 591 | 591 | } | |
| 592 | 592 | ||
| 593 | 593 | void Quax::rotateRight() { | |
| 594 | menulook->setItemChecked(lookid[look],false); | ||
| 595 | if (look==3) { | ||
| 596 | look=0; | ||
| 594 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 595 | if (m_lookAt==3) { | ||
| 596 | m_lookAt=0; | ||
| 597 | 597 | } else { | |
| 598 | look++; | ||
| 598 | m_lookAt++; | ||
| 599 | 599 | } | |
| 600 | menulook->setItemChecked(lookid[look],true); | ||
| 601 | rotate(look); | ||
| 600 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 601 | rotate(m_lookAt); | ||
| 602 | 602 | } | |
| 603 | 603 | ||
| 604 | 604 | void Quax::rotate(int pos) { | |
| … | … | ||
| 612 | 612 | void Quax::copyColor(int id) { | |
| 613 | 613 | ||
| 614 | 614 | if (id == colorid[1] ) { | |
| 615 | qApp->clipboard()->setText(colorStringDecimal); | ||
| 615 | qApp->clipboard()->setText(m_colorStringDecimal); | ||
| 616 | 616 | } else if (id == colorid[2]) { | |
| 617 | 617 | // this get called when user press Ctrl+C | |
| 618 | 618 | // | |
| 619 | 619 | // I must call grabForPixel because it's posible that | |
| 620 | 620 | // this slot get executed even user doesn't right click | |
| 621 | // on Quax, so updateMenuColor is not yet called and | ||
| 621 | // on Quax, so updatemenuColor is not yet called and | ||
| 622 | 622 | // variables may contain old or invalid color | |
| 623 | 623 | grabForPixel(); | |
| 624 | qApp->clipboard()->setText(colorStringHexaLower); | ||
| 624 | qApp->clipboard()->setText(m_colorStringHexaLower); | ||
| 625 | 625 | } else if (id == colorid[3] || id == 0) { | |
| 626 | 626 | // id=0 if user click when color tip is displayed | |
| 627 | qApp->clipboard()->setText(colorStringHexaUpper); | ||
| 627 | qApp->clipboard()->setText(m_colorStringHexaUpper); | ||
| 628 | 628 | } else { | |
| 629 | 629 | qWarning("id=%d: This must not happen",id); | |
| 630 | 630 | } | |
| … | … | ||
| 633 | 633 | void Quax::updateMenuColor() { | |
| 634 | 634 | grabForPixel(); | |
| 635 | 635 | #if QT_VERSION > 300 | |
| 636 | ///pixelColorIcon->clearGenerated(); | ||
| 636 | ///m_pixelColorIcon->clearGenerated(); | ||
| 637 | 637 | #endif | |
| 638 | pixelColorIcon->reset(pix_cursor,QIcon::Small); | ||
| 638 | m_pixelColorIcon->reset(pix_cursor,QIcon::Small); | ||
| 639 | 639 | ||
| 640 | 640 | menu->changeItem(colorid[0],QIcon(pix_cursor),QObject::tr("Copy Color")); | |
| 641 | menucolor->changeItem(colorid[1],colorStringDecimal); | ||
| 642 | menucolor->changeItem(colorid[2],colorStringHexaLower); | ||
| 643 | menucolor->changeItem(colorid[3],colorStringHexaUpper); | ||
| 641 | menuColor->changeItem(colorid[1],m_colorStringDecimal); | ||
| 642 | menuColor->changeItem(colorid[2],m_colorStringHexaLower); | ||
| 643 | menuColor->changeItem(colorid[3],m_colorStringHexaUpper); | ||
| 644 | 644 | } |
src/quax.h
(17 / 21)
|   | |||
| 17 | 17 | ||
| 18 | 18 | #include <qglobal.h> | |
| 19 | 19 | ||
| 20 | #include <qcursor.h> | ||
| 21 | 20 | #include <qpixmap.h> | |
| 22 | 21 | #include <qbitmap.h> | |
| 23 | 22 | #include <qimage.h> | |
| … | … | ||
| 42 | 42 | #define QUAX_VERSION "1.0" | |
| 43 | 43 | #define QUAX_RELEASE "1" | |
| 44 | 44 | ||
| 45 | #define PIX_CURSOR_SCALE 10 | ||
| 45 | //#define PIX_CURSOR_SCALE 10 | ||
| 46 | 46 | #define ZOOM_SCALE_MIN 2 | |
| 47 | 47 | #define ZOOM_SCALE_MAX 5 | |
| 48 | 48 | ||
| … | … | ||
| 80 | 80 | protected: | |
| 81 | 81 | /** | |
| 82 | 82 | * Show color tooltip when mouse enter Quax area, and set | |
| 83 | * the @p cursorOverQuax flag. | ||
| 83 | * the @p m_cursorOverQuax flag. | ||
| 84 | 84 | */ | |
| 85 | 85 | void enterEvent(QEvent *e); | |
| 86 | 86 | /** | |
| 87 | * Hide color tooltip if shown, and set the @p cursorOverQuax flag. | ||
| 87 | * Hide color tooltip if shown, and set the @p m_cursorOverQuax flag. | ||
| 88 | 88 | */ | |
| 89 | 89 | void leaveEvent(QEvent *e); | |
| 90 | 90 | /** | |
| … | … | ||
| 99 | 99 | /** | |
| 100 | 100 | * Executed when user release move the mouse. If the color tip is enabled, | |
| 101 | 101 | * then displayed color is updated as well the tooltip position. | |
| 102 | * If is @p inDrag is true, then Quax position is updated (dragged) | ||
| 102 | * If is @p m_inDrag is true, then Quax position is updated (dragged) | ||
| 103 | 103 | * to that of mouse position. | |
| 104 | 104 | */ | |
| 105 | 105 | void mouseMoveEvent(QMouseEvent *e); | |
| … | … | ||
| 129 | 129 | void wheelEvent(QWheelEvent *e); | |
| 130 | 130 | ||
| 131 | 131 | private: | |
| 132 | QString colorStringDecimal, ///< the current color under mouse as decimals comma seperated | ||
| 133 | colorStringHexaLower, ///< the current color under mouse as web RGB with lower hexadecimals | ||
| 134 | colorStringHexaUpper; ///< the current color under mouse as web RGB with upper hexadecimals | ||
| 135 | QIcon *pixelColorIcon; ///< The icon set which is used in QML content from @ref colorTip | ||
| 132 | QString m_colorStringDecimal, ///< the current color under mouse as decimals comma seperated | ||
| 133 | m_colorStringHexaLower, ///< the current color under mouse as web RGB with lower hexadecimals | ||
| 134 | m_colorStringHexaUpper; ///< the current color under mouse as web RGB with upper hexadecimals | ||
| 135 | QIcon *m_pixelColorIcon; ///< The icon set which is used in QML content from @ref colorTip | ||
| 136 | 136 | QLabel *colorTip; ///< The tool tip for displaying current color under mouse | |
| 137 | 137 | QMenu *menu, ///< The main menu of Quax | |
| 138 | *menuzoom, ///< Menu for zoom levels and zoom in and zoom out items | ||
| 139 | *menulook, ///< The "Look at" menu | ||
| 140 | *menucolor; ///< Menu for coying textual representation into clipboard | ||
| 138 | *menuZoom, ///< Menu for zoom levels and zoom in and zoom out items | ||
| 139 | *menuLook, ///< The "Look at" menu | ||
| 140 | *menuColor; ///< Menu for coying textual representation into clipboard | ||
| 141 | 141 | QPixmap pix, ///< Quax skin image | |
| 142 | 142 | pix_alpha, ///< Quax alpha mask for skin image | |
| 143 | 143 | pix_zoom, ///< The grabbed image zoomend and clipped | |
| 144 | 144 | pix_cursor; ///< The icon used in color menu item and color tooltip | |
| 145 | QCursor hand_cursor, ///< normal mouse cursor when mouse pointer is over Quax | ||
| 146 | cross_cursor, ///< cursor when color tooltip is displayed (cross) | ||
| 147 | copy_cursor; ///< cursor when user "take a shot" of current color | ||
| 148 | bool inDrag, ///< if true, the user is dragging the Quax | ||
| 149 | colorTipShowed, ///< if true, the color tooltip is displayed | ||
| 150 | cursorOverQuax, ///< if true, mouse cursor is over Quax surface | ||
| 151 | ctrlKeyOn; ///< if true, the Ctrl key is pressed down | ||
| 145 | bool m_inDrag, ///< if true, the user is dragging the Quax | ||
| 146 | m_colorTipShowed, ///< if true, the color tooltip is displayed | ||
| 147 | m_cursorOverQuax, ///< if true, mouse cursor is over Quax surface | ||
| 148 | m_ctrlKeyOn; ///< if true, the Ctrl key is pressed down | ||
| 149 | int m_zoom, ///< current zoom level | ||
| 150 | m_lookAt; ///< current quadrant direction where Quax "look at" | ||
| 152 | 151 | QPoint dragOffset; ///< the offset between Quax position and new mouse position | |
| 153 | 152 | QMap<int,int> zoomid, ///< mapping between zoom level and @ref menuzoom menu item ids | |
| 154 | 153 | lookid, ///< mapping between look direction and @ref menulook menu item ids | |
| 155 | 154 | colorid; ///< mapping between text color type and @ref menucolor menu item ids | |
| 156 | int zoom, ///< current zoom level | ||
| 157 | look; ///< current quadrant direction where Quax "look at" | ||
| 158 | 155 | ||
| 159 | 156 | /** | |
| 160 | 157 | * It grab desktop area, scale it, clip it with circle region, |

