Commit 432f01b73571dc467971559eccb953d0046328a6
- Diff rendering mode:
- inline
- side by side
src/quax.cpp
(124 / 136)
|   | |||
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | 48 | Quax::Quax() | |
| 49 | : QWidget(0,0,Qt::WStyle_Customize|Qt::WStyle_NoBorder|Qt::WType_TopLevel) | ||
| 49 | : QWidget(0, Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::FramelessWindowHint) | ||
| 50 | 50 | , m_colorStringDecimal("255, 255, 255") | |
| 51 | 51 | , m_colorStringHexaLower("#ffffff") | |
| 52 | 52 | , m_colorStringHexaUpper("#FFFFFF") | |
| 53 | 53 | , m_inDrag(false) | |
| 54 | 54 | , m_colorTipEnabled(false) | |
| 55 | , m_zoom(ZOOM_SCALE_MIN) | ||
| 55 | , m_zoomLevel(ZOOM_SCALE_MIN) | ||
| 56 | 56 | , m_lookAt(0) | |
| 57 | 57 | { | |
| 58 | 58 | // customize looks | |
| 59 | 59 | //setAttribute(Qt::WA_NoSystemBackground); | |
| 60 | 60 | setFixedSize(150, 150); | |
| 61 | 61 | setCursor(Qt::PointingHandCursor); | |
| 62 | setIcon(QPixmap(icon_xpm)); | ||
| 62 | setWindowIcon(QPixmap(icon_xpm)); | ||
| 63 | 63 | rotate(0); | |
| 64 | 64 | ||
| 65 | 65 | // build RMB popup menu | |
| 66 | 66 | menu = new QMenu(this); | |
| 67 | menuZoom = new QMenu(this); | ||
| 68 | menuZoom->setCheckable(true); | ||
| 69 | for (int i = ZOOM_SCALE_MIN; i <= ZOOM_SCALE_MAX; i++) | ||
| 70 | zoomid[i]=menuZoom->insertItem(tr("1:%1").arg(i), this, SLOT(zoomTo(int))); | ||
| 67 | |||
| 68 | menuZoom = new QMenu(tr("Zoom"), this); | ||
| 69 | menuZoom->setIcon(QPixmap(viewmag_xpm)); | ||
| 70 | m_zoomGroup = new QActionGroup(this); | ||
| 71 | for (int i = ZOOM_SCALE_MIN; i <= ZOOM_SCALE_MAX; i++) { | ||
| 72 | QAction * zoomAction = menuZoom->addAction(tr("%1:1").arg(i), this, SLOT(slotZoomTo())); | ||
| 73 | zoomAction->setCheckable(true); | ||
| 74 | zoomAction->setProperty("level", i); | ||
| 75 | zoomAction->setActionGroup(m_zoomGroup); | ||
| 76 | } | ||
| 71 | 77 | menuZoom->addSeparator(); | |
| 72 | menuZoom->insertItem(QPixmap(viewmagin_xpm),QObject::tr("Zoom In"), this, SLOT(zoomIn()),QKeySequence(QObject::tr("+","Zoom In"))); | ||
| 73 | menuZoom->insertItem(QPixmap(viewmagout_xpm),QObject::tr("Zoom Out"), this, SLOT(zoomOut()),QKeySequence(QObject::tr("-","Zoom Out"))); | ||
| 78 | menuZoom->addAction(QPixmap(viewmagin_xpm), tr("Zoom In"), this, SLOT(zoomIn()), QKeySequence(tr("+","Zoom In"))); | ||
| 79 | menuZoom->addAction(QPixmap(viewmagout_xpm), tr("Zoom Out"), this, SLOT(zoomOut()), QKeySequence(tr("-","Zoom Out"))); | ||
| 74 | 80 | ||
| 75 | menuLook = new QMenu(this); | ||
| 76 | menuLook->setCheckable(true); | ||
| 77 | lookid[1]=menuLook->insertItem(QObject::tr("North-West"), this, SLOT(rotateNorthWest()),QKeySequence(QObject::tr("U", "North-West"))); | ||
| 78 | lookid[0]=menuLook->insertItem(QObject::tr("South-West"), this, SLOT(rotateSouthWest()),QKeySequence(QObject::tr("J", "South-West"))); | ||
| 79 | lookid[2]=menuLook->insertItem(QObject::tr("North-East"), this, SLOT(rotateNorthEast()),QKeySequence(QObject::tr("I", "North-East"))); | ||
| 80 | lookid[3]=menuLook->insertItem(QObject::tr("South-East"), this, SLOT(rotateSouthEast()),QKeySequence(QObject::tr("K", "South-East"))); | ||
| 81 | menuLook->insertSeparator(); | ||
| 82 | menuLook->insertItem(QPixmap(left_xpm),QObject::tr("Rotate Left"), this, SLOT(rotateLeft()),QKeySequence(QObject::tr("L","Rotate Left"))); | ||
| 83 | menuLook->insertItem(QPixmap(right_xpm),QObject::tr("Rotate Right"), this, SLOT(rotateRight()),QKeySequence(QObject::tr("R","Rotate Right"))); | ||
| 81 | menuLook = new QMenu(tr("Look At"), this); | ||
| 82 | menuLook->setIcon(QPixmap(look_xpm)); | ||
| 83 | m_rotGroup = new QActionGroup(this); | ||
| 84 | QAction * r0 = menuLook->addAction(tr("North-West"), this, SLOT(slotRotate()), QKeySequence(tr("U", "North-West"))); | ||
| 85 | r0->setProperty("rotation", 0); | ||
| 86 | r0->setActionGroup(m_rotGroup); | ||
| 87 | QAction * r1 = menuLook->addAction(tr("South-West"), this, SLOT(slotRotate()), QKeySequence(tr("J", "South-West"))); | ||
| 88 | r1->setProperty("rotation", 1); | ||
| 89 | r1->setActionGroup(m_rotGroup); | ||
| 90 | QAction * r2 = menuLook->addAction(tr("North-East"), this, SLOT(slotRotate()), QKeySequence(tr("I", "North-East"))); | ||
| 91 | r2->setProperty("rotation", 2); | ||
| 92 | r2->setActionGroup(m_rotGroup); | ||
| 93 | QAction * r3 = menuLook->addAction(tr("South-Eash"), this, SLOT(slotRotate()), QKeySequence(tr("K", "South-East"))); | ||
| 94 | r3->setProperty("rotation", 3); | ||
| 95 | r3->setActionGroup(m_rotGroup); | ||
| 96 | menuLook->addSeparator(); | ||
| 97 | menuLook->addAction(QPixmap(left_xpm), tr("Rotate Left"), this, SLOT(slotRotateLeft()), QKeySequence(tr("L", "Rotate Left"))); | ||
| 98 | menuLook->addAction(QPixmap(right_xpm),tr("Rotate Right"), this, SLOT(slotRotateRight()), QKeySequence(tr("R", "Rotate Right"))); | ||
| 84 | 99 | ||
| 85 | menuColor = new QMenu(this); | ||
| 86 | colorid[1]=menuColor->insertItem(m_colorStringDecimal, this, SLOT(colorToClipboard(int))); | ||
| 87 | colorid[2]=menuColor->insertItem(m_colorStringHexaLower, this, SLOT(colorToClipboard(int)),QKeySequence(QObject::tr("Ctrl+C","Copy Color"))); | ||
| 88 | colorid[3]=menuColor->insertItem(m_colorStringHexaUpper, this, SLOT(colorToClipboard(int))); | ||
| 100 | menuColor = new QMenu(tr("Copy Color"), this); | ||
| 101 | m_colorGroup = new QActionGroup(this); | ||
| 102 | QAction * c0 = menuColor->addAction(m_colorStringDecimal, this, SLOT(slotColorToClipboard())); | ||
| 103 | c0->setActionGroup(m_colorGroup); | ||
| 104 | c0->setProperty("id", 0); | ||
| 105 | QAction * c1 = menuColor->addAction(m_colorStringHexaLower, this, SLOT(slotColorToClipboard())); | ||
| 106 | c1->setActionGroup(m_colorGroup); | ||
| 107 | c1->setProperty("id", 1); | ||
| 108 | QAction * c2 = menuColor->addAction(m_colorStringHexaUpper, this, SLOT(slotColorToClipboard())); | ||
| 109 | c2->setActionGroup(m_colorGroup); | ||
| 110 | c2->setProperty("id", 2); | ||
| 89 | 111 | ||
| 90 | menu->insertItem(QPixmap(viewmag_xpm),QObject::tr("Zoom"),menuZoom); | ||
| 91 | menu->insertItem(QPixmap(look_xpm),QObject::tr("Look At"),menuLook); | ||
| 92 | colorid[0]=menu->insertItem(m_colorPixmap,QObject::tr("Copy Color"),menuColor); | ||
| 93 | menu->insertItem(QPixmap(help_xpm),QObject::tr("Help"), this, SLOT(help()),QKeySequence(QObject::tr("H","Help"))); | ||
| 94 | menu->insertSeparator(); | ||
| 95 | menu->insertItem(QObject::tr("About Quax"), this, SLOT(about())); | ||
| 96 | menu->insertItem(QObject::tr("About Qt"), this, SLOT(aboutQt())); | ||
| 97 | menu->insertSeparator(); | ||
| 98 | menu->insertItem(QPixmap(exit_xpm),QObject::tr("Quit"),qApp,SLOT(quit()),QKeySequence(QObject::tr("Q","Quit"))); | ||
| 112 | menu->addMenu(menuZoom); | ||
| 113 | menu->addMenu(menuLook); | ||
| 114 | menu->addMenu(menuColor); | ||
| 115 | menu->addAction(QPixmap(help_xpm), tr("Help"), this, SLOT(slotHelp()), QKeySequence(tr("H", "Help"))); | ||
| 116 | menu->addSeparator(); | ||
| 117 | menu->addAction(tr("About Quax"), this, SLOT(slotAbout())); | ||
| 118 | menu->addAction(tr("About Qt"), this, SLOT(slotAboutQt())); | ||
| 119 | menu->addSeparator(); | ||
| 120 | menu->addAction(QPixmap(exit_xpm),tr("Quit"), qApp, SLOT(quit()), QKeySequence(tr("Q", "Quit"))); | ||
| 99 | 121 | ||
| 100 | menuZoom->setItemChecked(zoomid[m_zoom],true); | ||
| 101 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 102 | connect(menu,SIGNAL(aboutToShow()), this, SLOT(updatemenuColor())); | ||
| 122 | m_zoomGroup->actions().first()->setChecked(true); | ||
| 123 | m_rotGroup->actions().at(1)->setChecked(true); | ||
| 124 | connect(menu, SIGNAL(aboutToShow()), this, SLOT(slotUpdateColorMenu())); | ||
| 103 | 125 | ||
| 104 | 126 | // set the color tooltip | |
| 105 | 127 | m_colorTip = new QTextBrowser; | |
| 106 | 128 | m_colorTip->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::Tool | Qt::X11BypassWindowManagerHint); | |
| 107 | 129 | m_colorTip->setAlignment(Qt::AlignLeft | Qt::AlignTop); | |
| 108 | 130 | m_colorTip->setFrameStyle(QFrame::Plain | QFrame::Box); | |
| 109 | m_colorTip->setTextFormat(Qt::RichText); | ||
| 110 | 131 | m_colorTip->resize(120, 28); | |
| 111 | 132 | ||
| 112 | 133 | setMouseTracking(true); | |
| … | … | ||
| 184 | 184 | { | |
| 185 | 185 | if (e->modifiers() & Qt::ControlModifier) { | |
| 186 | 186 | if (e->delta() > 0) | |
| 187 | rotateLeft(); | ||
| 187 | slotRotateLeft(); | ||
| 188 | 188 | else | |
| 189 | rotateRight(); | ||
| 189 | slotRotateRight(); | ||
| 190 | 190 | } else { | |
| 191 | 191 | if (e->delta() > 0) | |
| 192 | zoomIn(); | ||
| 192 | slotZoomIn(); | ||
| 193 | 193 | else | |
| 194 | zoomOut(); | ||
| 194 | slotZoomOut(); | ||
| 195 | 195 | } | |
| 196 | 196 | e->accept(); | |
| 197 | 197 | if (m_colorTipEnabled && !m_colorTip->isHidden()) | |
| … | … | ||
| 203 | 203 | int x, y, w, h; | |
| 204 | 204 | int grabX, grabY, grabW, grabH, ofsX, ofsY; | |
| 205 | 205 | ||
| 206 | w = SHAPE_INNER_WIDTH / m_zoom; | ||
| 207 | h = SHAPE_INNER_HEIGHT / m_zoom; | ||
| 206 | w = SHAPE_INNER_WIDTH / m_zoomLevel; | ||
| 207 | h = SHAPE_INNER_HEIGHT / m_zoomLevel; | ||
| 208 | 208 | switch (m_lookAt) { | |
| 209 | 209 | case 0: // South-West | |
| 210 | 210 | default: | |
| … | … | ||
| 261 | 261 | p.drawPixmap(ofsX,ofsY,pix_temp); | |
| 262 | 262 | } | |
| 263 | 263 | ||
| 264 | m_zoomPixmap = grabPix.transformed(QTransform::fromScale((double)m_zoom,(double)m_zoom)); | ||
| 264 | m_zoomPixmap = grabPix.transformed(QTransform::fromScale((double)m_zoomLevel,(double)m_zoomLevel)); | ||
| 265 | 265 | update(); | |
| 266 | 266 | } | |
| 267 | 267 | ||
| … | … | ||
| 269 | 269 | { | |
| 270 | 270 | // get the color under cursor | |
| 271 | 271 | QPixmap grabPix = QPixmap::grabWindow(QApplication::desktop()->winId(), QCursor::pos().x() - 1, QCursor::pos().y() - 1, 1, 1); | |
| 272 | QImage img_grab = grabPix.convertToImage(); | ||
| 273 | QRgb rgb_color = img_grab.pixel(0, 0); | ||
| 272 | QRgb rgb_color = grabPix.toImage().pixel(0, 0); | ||
| 274 | 273 | m_colorStringDecimal = QString::number(qRed(rgb_color)) + ", " + | |
| 275 | 274 | QString::number(qGreen(rgb_color)) + ", " + | |
| 276 | 275 | QString::number(qBlue(rgb_color)); | |
| 277 | 276 | m_colorStringHexaLower.sprintf("#%02x%02x%02x",qRed(rgb_color),qGreen(rgb_color),qBlue(rgb_color)); | |
| 278 | m_colorStringHexaUpper = m_colorStringHexaLower.upper(); | ||
| 277 | m_colorStringHexaUpper = m_colorStringHexaLower.toUpper(); | ||
| 279 | 278 | ||
| 280 | 279 | // make a little pixmap with grabbed color | |
| 281 | 280 | m_colorPixmap = grabPix.scaled(14, 14); | |
| … | … | ||
| 309 | 309 | switch (e->button()) { | |
| 310 | 310 | case Qt::LeftButton: | |
| 311 | 311 | if (m_colorTipEnabled) { | |
| 312 | colorToClipboard(0); | ||
| 312 | slotColorToClipboard(); | ||
| 313 | 313 | setCursor(Qt::SizeAllCursor); | |
| 314 | 314 | } else { | |
| 315 | 315 | grabMouse(Qt::PointingHandCursor); | |
| … | … | ||
| 375 | 375 | break; | |
| 376 | 376 | case Qt::Key_Equal: | |
| 377 | 377 | case Qt::Key_Plus: | |
| 378 | zoomIn(); | ||
| 378 | slotZoomIn(); | ||
| 379 | 379 | break; | |
| 380 | 380 | case Qt::Key_Underscore: | |
| 381 | 381 | case Qt::Key_Minus: | |
| 382 | zoomOut(); | ||
| 382 | slotZoomOut(); | ||
| 383 | 383 | break; | |
| 384 | 384 | default: | |
| 385 | 385 | e->ignore(); | |
| … | … | ||
| 401 | 401 | } | |
| 402 | 402 | } | |
| 403 | 403 | ||
| 404 | void Quax::help() | ||
| 404 | void Quax::slotHelp() | ||
| 405 | 405 | { | |
| 406 | 406 | if (QDesktopServices::openUrl(QUrl("help:quax"))) | |
| 407 | 407 | return; | |
| … | … | ||
| 412 | 412 | QMessageBox::Ok); | |
| 413 | 413 | } | |
| 414 | 414 | ||
| 415 | void Quax::about() | ||
| 415 | void Quax::slotAbout() | ||
| 416 | 416 | { | |
| 417 | QMessageBox::about(this, QObject::tr("About Quax %1").arg(QUAX_VERSION "-" QUAX_RELEASE), QObject::tr( | ||
| 417 | QMessageBox::about(this, tr("About Quax %1").arg(QUAX_VERSION "-" QUAX_RELEASE), tr( | ||
| 418 | 418 | "<p><b>Quax</b> is a little magnifing tool for X. Quax homepage is " | |
| 419 | 419 | "at <tt><http://www.ro.kde.org/quax/></tt>." | |
| 420 | 420 | "</p><p>This is Quax version %1." | |
| … | … | ||
| 429 | 429 | "</dl></p>").arg(QUAX_VERSION "-" QUAX_RELEASE)); | |
| 430 | 430 | } | |
| 431 | 431 | ||
| 432 | void Quax::aboutQt() | ||
| 432 | void Quax::slotAboutQt() | ||
| 433 | 433 | { | |
| 434 | 434 | QMessageBox::aboutQt(this, tr("About Qt")); | |
| 435 | 435 | } | |
| 436 | 436 | ||
| 437 | void Quax::zoomIn() | ||
| 437 | void Quax::slotZoomIn() | ||
| 438 | 438 | { | |
| 439 | if (m_zoom >= ZOOM_SCALE_MAX) | ||
| 440 | return; | ||
| 441 | menuZoom->setItemChecked(zoomid[m_zoom], false); | ||
| 442 | m_zoom++; | ||
| 443 | menuZoom->setItemChecked(zoomid[m_zoom], true); | ||
| 439 | if (m_zoomLevel < ZOOM_SCALE_MAX) { | ||
| 440 | m_zoomLevel++; | ||
| 441 | foreach (QAction * action, m_zoomGroup->actions()) | ||
| 442 | if (action->property("level").toInt() == m_zoomLevel) | ||
| 443 | action->setChecked(true); | ||
| 444 | } | ||
| 444 | 445 | } | |
| 445 | 446 | ||
| 446 | void Quax::zoomOut() | ||
| 447 | void Quax::slotZoomOut() | ||
| 447 | 448 | { | |
| 448 | if (m_zoom <= ZOOM_SCALE_MIN) | ||
| 449 | return; | ||
| 450 | menuZoom->setItemChecked(zoomid[m_zoom], false); | ||
| 451 | m_zoom--; | ||
| 452 | menuZoom->setItemChecked(zoomid[m_zoom], true); | ||
| 449 | if (m_zoomLevel > ZOOM_SCALE_MIN) { | ||
| 450 | m_zoomLevel--; | ||
| 451 | foreach (QAction * action, m_zoomGroup->actions()) | ||
| 452 | if (action->property("level").toInt() == m_zoomLevel) | ||
| 453 | action->setChecked(true); | ||
| 454 | } | ||
| 453 | 455 | } | |
| 454 | 456 | ||
| 455 | void Quax::zoomTo(int pos) | ||
| 457 | void Quax::slotZoomTo() | ||
| 456 | 458 | { | |
| 457 | for (int i = ZOOM_SCALE_MIN; i <= ZOOM_SCALE_MAX; i++) | ||
| 458 | if (zoomid[i]==pos) { | ||
| 459 | menuZoom->setItemChecked(zoomid[i], true); | ||
| 460 | m_zoom=i; | ||
| 461 | } else { | ||
| 462 | menuZoom->setItemChecked(zoomid[i], false); | ||
| 463 | } | ||
| 459 | QAction * action = static_cast<QAction *>(sender()); | ||
| 460 | m_zoomLevel = action->property("level").toInt(); | ||
| 464 | 461 | } | |
| 465 | 462 | ||
| 466 | void Quax::rotateNorthWest() | ||
| 463 | void Quax::slotRotate() | ||
| 467 | 464 | { | |
| 468 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 469 | m_lookAt = 1; | ||
| 470 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 465 | QAction * action = static_cast<QAction *>(sender()); | ||
| 466 | m_lookAt = action->property("rotation").toInt(); | ||
| 471 | 467 | rotate(m_lookAt); | |
| 472 | 468 | } | |
| 473 | 469 | ||
| 474 | void Quax::rotateSouthWest() | ||
| 470 | void Quax::slotRotateLeft() | ||
| 475 | 471 | { | |
| 476 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 477 | m_lookAt = 0; | ||
| 478 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 472 | m_lookAt = !m_lookAt ? 3 : m_lookAt - 1; | ||
| 473 | m_rotGroup->actions().at(m_lookAt)->setChecked(true); | ||
| 479 | 474 | rotate(m_lookAt); | |
| 480 | 475 | } | |
| 481 | 476 | ||
| 482 | void Quax::rotateNorthEast() | ||
| 477 | void Quax::slotRotateRight() | ||
| 483 | 478 | { | |
| 484 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 485 | m_lookAt = 2; | ||
| 486 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 479 | m_lookAt = m_lookAt == 3 ? 0 : m_lookAt + 1; | ||
| 480 | m_rotGroup->actions().at(m_lookAt)->setChecked(true); | ||
| 487 | 481 | rotate(m_lookAt); | |
| 488 | 482 | } | |
| 489 | 483 | ||
| 490 | void Quax::rotateSouthEast() | ||
| 491 | { | ||
| 492 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 493 | m_lookAt = 3; | ||
| 494 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 495 | rotate(m_lookAt); | ||
| 496 | } | ||
| 497 | |||
| 498 | void Quax::rotateLeft() | ||
| 499 | { | ||
| 500 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 501 | if (m_lookAt == 0) | ||
| 502 | m_lookAt = 3; | ||
| 503 | else | ||
| 504 | m_lookAt--; | ||
| 505 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 506 | rotate(m_lookAt); | ||
| 507 | } | ||
| 508 | |||
| 509 | void Quax::rotateRight() | ||
| 510 | { | ||
| 511 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 512 | if (m_lookAt == 3) | ||
| 513 | m_lookAt = 0; | ||
| 514 | else | ||
| 515 | m_lookAt++; | ||
| 516 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 517 | rotate(m_lookAt); | ||
| 518 | } | ||
| 519 | |||
| 520 | 484 | void Quax::rotate(int pos) | |
| 521 | 485 | { | |
| 522 | 486 | QTransform rot; | |
| … | … | ||
| 491 | 491 | setMask(QPixmap(mag_alpha_xpm).transformed(rot).mask()); | |
| 492 | 492 | } | |
| 493 | 493 | ||
| 494 | void Quax::colorToClipboard(int id) | ||
| 494 | void Quax::slotColorToClipboard() | ||
| 495 | 495 | { | |
| 496 | if (id == colorid[1]) { | ||
| 497 | qApp->clipboard()->setText(m_colorStringDecimal); | ||
| 498 | } else if (id == colorid[2]) { | ||
| 499 | // this get called when user press Ctrl+C | ||
| 500 | // | ||
| 501 | // I must call grabForPixel because it's posible that | ||
| 502 | // this slot get executed even user doesn't right click | ||
| 503 | // on Quax, so updatemenuColor is not yet called and | ||
| 504 | // variables may contain old or invalid color | ||
| 505 | grabForPixel(); | ||
| 506 | qApp->clipboard()->setText(m_colorStringHexaLower); | ||
| 507 | } else if (id == colorid[3] || id == 0) { | ||
| 508 | // id=0 if user click when color tip is displayed | ||
| 509 | qApp->clipboard()->setText(m_colorStringHexaUpper); | ||
| 510 | } else | ||
| 511 | qWarning("id=%d: This must not happen",id); | ||
| 496 | QAction * action = dynamic_cast<QAction *>(sender()); | ||
| 497 | int id = action ? action->property("id").toInt() : 2; | ||
| 498 | switch (id) { | ||
| 499 | case 0: | ||
| 500 | qApp->clipboard()->setText(m_colorStringDecimal); | ||
| 501 | break; | ||
| 502 | case 1: | ||
| 503 | // this get called when user press Ctrl+C | ||
| 504 | // | ||
| 505 | // I must call grabForPixel because it's posible that | ||
| 506 | // this slot get executed even user doesn't right click | ||
| 507 | // on Quax, so slotUpdateColorMenu is not yet called and | ||
| 508 | // variables may contain old or invalid color | ||
| 509 | grabForPixel(); | ||
| 510 | qApp->clipboard()->setText(m_colorStringHexaLower); | ||
| 511 | break; | ||
| 512 | case 2: | ||
| 513 | qApp->clipboard()->setText(m_colorStringHexaUpper); | ||
| 514 | break; | ||
| 515 | } | ||
| 512 | 516 | } | |
| 513 | 517 | ||
| 514 | void Quax::updateMenuColor() | ||
| 518 | void Quax::slotUpdateColorMenu() | ||
| 515 | 519 | { | |
| 516 | 520 | grabForPixel(); | |
| 517 | menu->changeItem(colorid[0], QIcon(m_colorPixmap), QObject::tr("Copy Color")); | ||
| 518 | menuColor->changeItem(colorid[1], m_colorStringDecimal); | ||
| 519 | menuColor->changeItem(colorid[2], m_colorStringHexaLower); | ||
| 520 | menuColor->changeItem(colorid[3], m_colorStringHexaUpper); | ||
| 521 | menuColor->setIcon(QIcon(m_colorPixmap)); | ||
| 522 | m_colorGroup->actions().at(0)->setText(m_colorStringDecimal); | ||
| 523 | m_colorGroup->actions().at(1)->setText(m_colorStringHexaLower); | ||
| 524 | m_colorGroup->actions().at(2)->setText(m_colorStringHexaUpper); | ||
| 521 | 525 | } |
src/quax.h
(18 / 33)
|   | |||
| 21 | 21 | #include <qbitmap.h> | |
| 22 | 22 | #include <qimage.h> | |
| 23 | 23 | #include <qpainter.h> | |
| 24 | #include <qmap.h> | ||
| 25 | 24 | ||
| 26 | 25 | #include <qicon.h> | |
| 27 | 26 | #include <qwidget.h> | |
| … | … | ||
| 42 | 42 | #define QUAX_VERSION "1.0" | |
| 43 | 43 | #define QUAX_RELEASE "1" | |
| 44 | 44 | ||
| 45 | //#define PIX_CURSOR_SCALE 10 | ||
| 46 | 45 | #define ZOOM_SCALE_MIN 2 | |
| 47 | 46 | #define ZOOM_SCALE_MAX 5 | |
| 48 | 47 | ||
| … | … | ||
| 130 | 130 | QString m_colorStringDecimal, ///< the current color under mouse as decimals comma seperated | |
| 131 | 131 | m_colorStringHexaLower, ///< the current color under mouse as web RGB with lower hexadecimals | |
| 132 | 132 | m_colorStringHexaUpper; ///< the current color under mouse as web RGB with upper hexadecimals | |
| 133 | QMenu *menu, ///< The main menu of Quax | ||
| 134 | *menuZoom, ///< Menu for zoom levels and zoom in and zoom out items | ||
| 133 | QMenu *menu, ///< The main menu of Quax | ||
| 134 | *menuZoom, ///< Menu for zoom levels and zoom in and zoom out items | ||
| 135 | 135 | *menuLook, ///< The "Look at" menu | |
| 136 | 136 | *menuColor; ///< Menu for coying textual representation into clipboard | |
| 137 | QActionGroup *m_zoomGroup, | ||
| 138 | *m_rotGroup, | ||
| 139 | *m_colorGroup; | ||
| 137 | 140 | QTextBrowser *m_colorTip; ///< The tool tip for displaying current color under mouse | |
| 138 | 141 | QPixmap m_zoomPixmap, ///< The grabbed image zoomend and clipped | |
| 139 | 142 | m_colorPixmap; ///< The icon used in color menu item and color tooltip | |
| 140 | 143 | bool m_inDrag, ///< if true, the user is dragging the Quax | |
| 141 | 144 | m_colorTipEnabled;///< if true, the color tooltip is displayed | |
| 142 | int m_zoom, ///< current zoom level | ||
| 143 | m_lookAt; ///< current quadrant direction where Quax "look at" | ||
| 145 | int m_zoomLevel, ///< current zoom level | ||
| 146 | m_lookAt; ///< current quadrant direction where Quax "look at" | ||
| 144 | 147 | QPoint dragOffset; ///< the offset between Quax position and new mouse position | |
| 145 | QMap<int,int> zoomid, ///< mapping between zoom level and @ref menuzoom menu item ids | ||
| 146 | lookid, ///< mapping between look direction and @ref menulook menu item ids | ||
| 147 | colorid; ///< mapping between text color type and @ref menucolor menu item ids | ||
| 148 | 148 | ||
| 149 | 149 | /** | |
| 150 | 150 | * It grabs the desktop area, scale it, clip it with circle region, | |
| … | … | ||
| 166 | 166 | /** | |
| 167 | 167 | * Display manual page or open help center according with underling desktop environment. | |
| 168 | 168 | */ | |
| 169 | void help(); | ||
| 169 | void slotHelp(); | ||
| 170 | 170 | /** | |
| 171 | 171 | * Open Quax "about" messagebox with author list and some other | |
| 172 | 172 | * usefull information (copyright, version). | |
| 173 | 173 | */ | |
| 174 | void about(); | ||
| 174 | void slotAbout(); | ||
| 175 | 175 | /** | |
| 176 | 176 | * Open Trolltech standard "about" messagebox. | |
| 177 | 177 | */ | |
| 178 | void aboutQt(); | ||
| 178 | void slotAboutQt(); | ||
| 179 | 179 | /** | |
| 180 | 180 | * Scale up grabed desktop area if not at maximum zoom value. | |
| 181 | 181 | */ | |
| 182 | void zoomIn(); | ||
| 182 | void slotZoomIn(); | ||
| 183 | 183 | /** | |
| 184 | 184 | * Scale down grabed desktop area if not at minimum zoom value. | |
| 185 | 185 | */ | |
| 186 | void zoomOut(); | ||
| 186 | void slotZoomOut(); | ||
| 187 | 187 | /** | |
| 188 | 188 | * Zoom grabed desktop area to the @p pos level. | |
| 189 | 189 | * @param pos represent position into zoom menu, as well the zoom level | |
| 190 | 190 | */ | |
| 191 | void zoomTo(int pos); | ||
| 191 | void slotZoomTo(); | ||
| 192 | 192 | /** | |
| 193 | 193 | * Move the Quax point of desktop area grab to the North-West direction. | |
| 194 | 194 | * It make use of @ref Quax::rotate | |
| 195 | 195 | */ | |
| 196 | void rotateNorthWest(); | ||
| 196 | void slotRotate(); | ||
| 197 | 197 | /** | |
| 198 | * Move the Quax point of desktop area grab to the South-West direction. | ||
| 199 | */ | ||
| 200 | void rotateSouthWest(); | ||
| 201 | /** | ||
| 202 | * Move the Quax point of desktop area grab to the North-East direction. | ||
| 203 | */ | ||
| 204 | void rotateNorthEast(); | ||
| 205 | /** | ||
| 206 | * Move the Quax point of desktop area grab to the South-East direction. | ||
| 207 | */ | ||
| 208 | void rotateSouthEast(); | ||
| 209 | /** | ||
| 210 | 198 | * Rotate Quax point of desktop area grab to the left (counter-clockwise). | |
| 211 | 199 | */ | |
| 212 | void rotateLeft(); | ||
| 200 | void slotRotateLeft(); | ||
| 213 | 201 | /** | |
| 214 | 202 | * Rotate Quax point of desktop area grab to the right (clockwise). | |
| 215 | 203 | */ | |
| 216 | void rotateRight(); | ||
| 204 | void slotRotateRight(); | ||
| 217 | 205 | /** | |
| 218 | 206 | * Rotate Quax point of desktop area to the @p pos quadrant. | |
| 219 | 207 | * @param pos quadrant number (0..3) | |
| … | … | ||
| 212 | 212 | * @p colorStringHexaLower and @p colorStringHexaUpper into system | |
| 213 | 213 | * clipboard. For the menu item which handle "Ctrl+C" accelerator, it call | |
| 214 | 214 | * @ref grabForPixel() prior to cliboard operation. | |
| 215 | * @param id the menu identificator to get what color menu item was selected | ||
| 216 | 215 | */ | |
| 217 | void colorToClipboard(int id); | ||
| 216 | void slotColorToClipboard(); | ||
| 218 | 217 | /** | |
| 219 | 218 | * Build the menu left pixmap from the grabed color under mouse. This is slot is | |
| 220 | 219 | * called from QPopupMenu::aboutToShow signal. | |
| 221 | 220 | */ | |
| 222 | void updateMenuColor(); | ||
| 221 | void slotUpdateColorMenu(); | ||
| 223 | 222 | }; | |
| 224 | 223 | ||
| 225 | 224 | #endif |
src/quax.pro
(1 / 1)
|   | |||
| 8 | 8 | INCLUDEPATH += . | |
| 9 | 9 | ||
| 10 | 10 | #The following line was inserted by qt3to4 | |
| 11 | QT += qt3support | ||
| 11 | #QT += qt3support | ||
| 12 | 12 | ||
| 13 | 13 | # Input | |
| 14 | 14 | HEADERS += quax.h |

