Commit d42b4ccdd703c47ee74db36bb49d863d212bd2b4
- Diff rendering mode:
- inline
- side by side
src/quax.cpp
(53 / 50)
|   | |||
| 12 | 12 | // | |
| 13 | 13 | // | |
| 14 | 14 | ||
| 15 | #include "quax.h" | ||
| 16 | |||
| 15 | 17 | #include "mag.xpm" | |
| 16 | 18 | #include "mag-alpha.xpm" | |
| 17 | 19 | #include "exit.xpm" | |
| … | … | ||
| 26 | 26 | #include "icon.xpm" | |
| 27 | 27 | #include "help.xpm" | |
| 28 | 28 | ||
| 29 | #include "quax.h" | ||
| 30 | |||
| 31 | #include <QToolTip> | ||
| 29 | #include <QApplication> | ||
| 30 | #include <QClipboard> | ||
| 32 | 31 | #include <QColor> | |
| 33 | 32 | #include <QCursor> | |
| 34 | #include <QClipboard> | ||
| 35 | #include <QProcess> | ||
| 36 | 33 | #include <QDesktopServices> | |
| 37 | #include <QUrl> | ||
| 38 | #include <QTimerEvent> | ||
| 34 | #include <QDesktopWidget> | ||
| 39 | 35 | #include <QKeyEvent> | |
| 40 | #include <QLabel> | ||
| 41 | #include <QPixmap> | ||
| 42 | 36 | #include <QMenu> | |
| 37 | #include <QMessageBox> | ||
| 43 | 38 | #include <QMouseEvent> | |
| 44 | #include <QEvent> | ||
| 45 | 39 | #include <QPaintEvent> | |
| 40 | #include <QPainter> | ||
| 41 | #include <QPixmap> | ||
| 42 | #include <QProcess> | ||
| 43 | #include <QToolTip> | ||
| 44 | #include <QUrl> | ||
| 46 | 45 | #include <QWheelEvent> | |
| 47 | #include <QDesktopWidget> | ||
| 48 | 46 | ||
| 49 | 47 | ||
| 50 | 48 | Quax::Quax() | |
| … | … | ||
| 57 | 57 | { | |
| 58 | 58 | // customize looks | |
| 59 | 59 | //setAttribute(Qt::WA_NoSystemBackground); | |
| 60 | //setAttribute(Qt::WA_TranslucentBackground, true); | ||
| 60 | 61 | setFixedSize(150, 150); | |
| 61 | 62 | setCursor(Qt::PointingHandCursor); | |
| 62 | 63 | setWindowIcon(QPixmap(icon_xpm)); | |
| 63 | 64 | rotate(0); | |
| 64 | 65 | ||
| 65 | 66 | // build RMB popup menu | |
| 66 | menu = new QMenu(this); | ||
| 67 | |||
| 68 | menuZoom = new QMenu(tr("Zoom"), this); | ||
| 69 | menuZoom->setIcon(QPixmap(viewmag_xpm)); | ||
| 67 | m_menuZoom = new QMenu(tr("Zoom"), this); | ||
| 68 | m_menuZoom->setIcon(QPixmap(viewmag_xpm)); | ||
| 70 | 69 | m_zoomGroup = new QActionGroup(this); | |
| 71 | 70 | for (int i = ZOOM_SCALE_MIN; i <= ZOOM_SCALE_MAX; i++) { | |
| 72 | QAction * zoomAction = menuZoom->addAction(tr("%1:1").arg(i), this, SLOT(slotZoomTo())); | ||
| 71 | QAction * zoomAction = m_menuZoom->addAction(tr("%1:1").arg(i), this, SLOT(slotZoomTo())); | ||
| 73 | 72 | zoomAction->setCheckable(true); | |
| 74 | 73 | zoomAction->setProperty("level", i); | |
| 75 | 74 | zoomAction->setActionGroup(m_zoomGroup); | |
| 76 | 75 | } | |
| 77 | menuZoom->addSeparator(); | ||
| 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"))); | ||
| 76 | m_menuZoom->addSeparator(); | ||
| 77 | m_menuZoom->addAction(QPixmap(viewmagin_xpm), tr("Zoom In"), this, SLOT(slotZoomIn()), QKeySequence(tr("+","Zoom In"))); | ||
| 78 | m_menuZoom->addAction(QPixmap(viewmagout_xpm), tr("Zoom Out"), this, SLOT(slotZoomOut()), QKeySequence(tr("-","Zoom Out"))); | ||
| 80 | 79 | ||
| 81 | menuLook = new QMenu(tr("Look At"), this); | ||
| 82 | menuLook->setIcon(QPixmap(look_xpm)); | ||
| 80 | m_menuLook = new QMenu(tr("Look At"), this); | ||
| 81 | m_menuLook->setIcon(QPixmap(look_xpm)); | ||
| 83 | 82 | m_rotGroup = new QActionGroup(this); | |
| 84 | QAction * r0 = menuLook->addAction(tr("North-West"), this, SLOT(slotRotate()), QKeySequence(tr("U", "North-West"))); | ||
| 83 | QAction * r0 = m_menuLook->addAction(tr("North-West"), this, SLOT(slotRotate()), QKeySequence(tr("U", "North-West"))); | ||
| 85 | 84 | r0->setProperty("rotation", 0); | |
| 86 | 85 | r0->setActionGroup(m_rotGroup); | |
| 87 | QAction * r1 = menuLook->addAction(tr("South-West"), this, SLOT(slotRotate()), QKeySequence(tr("J", "South-West"))); | ||
| 86 | QAction * r1 = m_menuLook->addAction(tr("South-West"), this, SLOT(slotRotate()), QKeySequence(tr("J", "South-West"))); | ||
| 88 | 87 | r1->setProperty("rotation", 1); | |
| 89 | 88 | r1->setActionGroup(m_rotGroup); | |
| 90 | QAction * r2 = menuLook->addAction(tr("North-East"), this, SLOT(slotRotate()), QKeySequence(tr("I", "North-East"))); | ||
| 89 | QAction * r2 = m_menuLook->addAction(tr("North-East"), this, SLOT(slotRotate()), QKeySequence(tr("I", "North-East"))); | ||
| 91 | 90 | r2->setProperty("rotation", 2); | |
| 92 | 91 | r2->setActionGroup(m_rotGroup); | |
| 93 | QAction * r3 = menuLook->addAction(tr("South-Eash"), this, SLOT(slotRotate()), QKeySequence(tr("K", "South-East"))); | ||
| 92 | QAction * r3 = m_menuLook->addAction(tr("South-Eash"), this, SLOT(slotRotate()), QKeySequence(tr("K", "South-East"))); | ||
| 94 | 93 | r3->setProperty("rotation", 3); | |
| 95 | 94 | 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"))); | ||
| 95 | m_menuLook->addSeparator(); | ||
| 96 | m_menuLook->addAction(QPixmap(left_xpm), tr("Rotate Left"), this, SLOT(slotRotateLeft()), QKeySequence(tr("L", "Rotate Left"))); | ||
| 97 | m_menuLook->addAction(QPixmap(right_xpm),tr("Rotate Right"), this, SLOT(slotRotateRight()), QKeySequence(tr("R", "Rotate Right"))); | ||
| 99 | 98 | ||
| 100 | menuColor = new QMenu(tr("Copy Color"), this); | ||
| 99 | m_menuColor = new QMenu(tr("Copy Color"), this); | ||
| 101 | 100 | m_colorGroup = new QActionGroup(this); | |
| 102 | QAction * c0 = menuColor->addAction(m_colorStringDecimal, this, SLOT(slotColorToClipboard())); | ||
| 101 | QAction * c0 = m_menuColor->addAction(m_colorStringDecimal, this, SLOT(slotColorToClipboard())); | ||
| 103 | 102 | c0->setActionGroup(m_colorGroup); | |
| 104 | 103 | c0->setProperty("id", 0); | |
| 105 | QAction * c1 = menuColor->addAction(m_colorStringHexaLower, this, SLOT(slotColorToClipboard())); | ||
| 104 | QAction * c1 = m_menuColor->addAction(m_colorStringHexaLower, this, SLOT(slotColorToClipboard())); | ||
| 106 | 105 | c1->setActionGroup(m_colorGroup); | |
| 107 | 106 | c1->setProperty("id", 1); | |
| 108 | QAction * c2 = menuColor->addAction(m_colorStringHexaUpper, this, SLOT(slotColorToClipboard())); | ||
| 107 | QAction * c2 = m_menuColor->addAction(m_colorStringHexaUpper, this, SLOT(slotColorToClipboard())); | ||
| 109 | 108 | c2->setActionGroup(m_colorGroup); | |
| 110 | 109 | c2->setProperty("id", 2); | |
| 111 | 110 | ||
| 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"))); | ||
| 111 | m_menu = new QMenu(this); | ||
| 112 | m_menu->addMenu(m_menuZoom); | ||
| 113 | m_menu->addMenu(m_menuLook); | ||
| 114 | m_menu->addMenu(m_menuColor); | ||
| 115 | m_menu->addAction(QPixmap(help_xpm), tr("Help"), this, SLOT(slotHelp()), QKeySequence(tr("H", "Help"))); | ||
| 116 | m_menu->addSeparator(); | ||
| 117 | m_menu->addAction(tr("About Quax"), this, SLOT(slotAbout())); | ||
| 118 | m_menu->addAction(tr("About Qt"), this, SLOT(slotAboutQt())); | ||
| 119 | m_menu->addSeparator(); | ||
| 120 | m_menu->addAction(QPixmap(exit_xpm),tr("Quit"), qApp, SLOT(quit()), QKeySequence(tr("Q", "Quit"))); | ||
| 121 | connect(m_menu, SIGNAL(aboutToShow()), this, SLOT(slotUpdateColorMenu())); | ||
| 121 | 122 | ||
| 122 | 123 | m_zoomGroup->actions().first()->setChecked(true); | |
| 123 | 124 | m_rotGroup->actions().at(1)->setChecked(true); | |
| 124 | connect(menu, SIGNAL(aboutToShow()), this, SLOT(slotUpdateColorMenu())); | ||
| 125 | 125 | ||
| 126 | 126 | // set the color tooltip | |
| 127 | 127 | m_colorTip = new QTextBrowser; | |
| … | … | ||
| 134 | 134 | startTimer(UPDATE); | |
| 135 | 135 | } | |
| 136 | 136 | ||
| 137 | |||
| 138 | 137 | Quax::~Quax() | |
| 139 | 138 | { | |
| 140 | 139 | delete m_colorTip; | |
| … | … | ||
| 313 | 313 | } else { | |
| 314 | 314 | grabMouse(Qt::PointingHandCursor); | |
| 315 | 315 | m_inDrag = true; | |
| 316 | dragOffset = QCursor::pos() - QPoint(geometry().left(),geometry().top()); | ||
| 316 | m_dragOffset = QCursor::pos() - QPoint(geometry().left(),geometry().top()); | ||
| 317 | 317 | } | |
| 318 | 318 | break; | |
| 319 | 319 | case Qt::RightButton: | |
| 320 | menu->popup(QCursor::pos()); | ||
| 320 | m_menu->popup(QCursor::pos()); | ||
| 321 | 321 | break; | |
| 322 | 322 | default: | |
| 323 | 323 | break; | |
| … | … | ||
| 329 | 329 | if (m_colorTipEnabled) | |
| 330 | 330 | genColorTip(); | |
| 331 | 331 | if (m_inDrag && this == mouseGrabber()) | |
| 332 | move(QCursor::pos() - dragOffset); | ||
| 332 | move(QCursor::pos() - m_dragOffset); | ||
| 333 | 333 | } | |
| 334 | 334 | ||
| 335 | 335 | void Quax::mouseReleaseEvent(QMouseEvent *e) | |
| … | … | ||
| 376 | 376 | case Qt::Key_Plus: | |
| 377 | 377 | slotZoomIn(); | |
| 378 | 378 | break; | |
| 379 | case Qt::Key_R: | ||
| 380 | slotRotateRight(); | ||
| 381 | break; | ||
| 379 | 382 | case Qt::Key_Underscore: | |
| 380 | 383 | case Qt::Key_Minus: | |
| 381 | 384 | slotZoomOut(); | |
| 382 | 385 | break; | |
| 383 | 386 | default: | |
| 384 | e->ignore(); | ||
| 387 | QWidget::keyPressEvent(e); | ||
| 385 | 388 | return; | |
| 386 | 389 | } | |
| 387 | 390 | if (e->modifiers() & Qt::ShiftModifier) | |
| … | … | ||
| 401 | 401 | setCursor(Qt::PointingHandCursor); | |
| 402 | 402 | } | |
| 403 | 403 | } | |
| 404 | QWidget::keyReleaseEvent(e); | ||
| 404 | 405 | } | |
| 405 | 406 | ||
| 406 | 407 | void Quax::slotHelp() | |
| … | … | ||
| 417 | 417 | ||
| 418 | 418 | void Quax::slotAbout() | |
| 419 | 419 | { | |
| 420 | QMessageBox::about(this, tr("About Quax %1").arg(QUAX_VERSION "-" QUAX_RELEASE), tr( | ||
| 420 | QMessageBox::about(this, tr("About Quax %1").arg(qApp->applicationVersion()), tr( | ||
| 421 | 421 | "<p><b>Quax</b> is a little magnifing tool for X. Quax homepage is " | |
| 422 | 422 | "at <tt><http://www.ro.kde.org/quax/></tt>." | |
| 423 | 423 | "</p><p>This is Quax version %1." | |
| … | … | ||
| 429 | 429 | "<dd>porting to Qt4 and cleanups</dd>" | |
| 430 | 430 | "<dt><nobr>Vlad Oancea <tt><xtrim@fx.ro></tt></nobr></dt>" | |
| 431 | 431 | "<dd>Quax skin design</dd>" | |
| 432 | "</dl></p>").arg(QUAX_VERSION "-" QUAX_RELEASE)); | ||
| 432 | "</dl></p>").arg(qApp->applicationVersion())); | ||
| 433 | 433 | } | |
| 434 | 434 | ||
| 435 | 435 | void Quax::slotAboutQt() | |
| … | … | ||
| 521 | 521 | void Quax::slotUpdateColorMenu() | |
| 522 | 522 | { | |
| 523 | 523 | grabForPixel(); | |
| 524 | menuColor->setIcon(QIcon(m_colorPixmap)); | ||
| 524 | m_menuColor->setIcon(QIcon(m_colorPixmap)); | ||
| 525 | 525 | m_colorGroup->actions().at(0)->setText(m_colorStringDecimal); | |
| 526 | 526 | m_colorGroup->actions().at(1)->setText(m_colorStringHexaLower); | |
| 527 | 527 | m_colorGroup->actions().at(2)->setText(m_colorStringHexaUpper); |
src/quax.h
(12 / 30)
|   | |||
| 15 | 15 | #ifndef __quax_h__ | |
| 16 | 16 | #define __quax_h__ | |
| 17 | 17 | ||
| 18 | #include <qglobal.h> | ||
| 19 | |||
| 20 | #include <qpixmap.h> | ||
| 21 | #include <qbitmap.h> | ||
| 22 | #include <qimage.h> | ||
| 23 | #include <qpainter.h> | ||
| 24 | |||
| 25 | #include <qicon.h> | ||
| 26 | #include <qwidget.h> | ||
| 27 | #include <qlabel.h> | ||
| 28 | #include <qmessagebox.h> | ||
| 29 | #include <qapplication.h> | ||
| 30 | #include <qmatrix.h> | ||
| 31 | #include <qapplication.h> | ||
| 32 | //Added by qt3to4: | ||
| 33 | #include <QMenu> | ||
| 34 | #include <QWheelEvent> | ||
| 18 | #include <QBitmap> | ||
| 35 | 19 | #include <QEvent> | |
| 36 | #include <QMouseEvent> | ||
| 37 | #include <QTimerEvent> | ||
| 38 | #include <QKeyEvent> | ||
| 39 | #include <QPaintEvent> | ||
| 20 | #include <QIcon> | ||
| 21 | #include <QImage> | ||
| 22 | #include <QMenu> | ||
| 23 | #include <QPixmap> | ||
| 40 | 24 | #include <QTextBrowser> | |
| 25 | #include <QWidget> | ||
| 41 | 26 | ||
| 42 | #define QUAX_VERSION "1.0" | ||
| 43 | #define QUAX_RELEASE "1" | ||
| 44 | |||
| 45 | 27 | #define ZOOM_SCALE_MIN 2 | |
| 46 | #define ZOOM_SCALE_MAX 5 | ||
| 28 | #define ZOOM_SCALE_MAX 8 | ||
| 47 | 29 | ||
| 48 | 30 | #define SHAPE_WIDTH 150 | |
| 49 | 31 | #define SHAPE_HEIGHT 150 | |
| … | … | ||
| 112 | 112 | QString m_colorStringDecimal, ///< the current color under mouse as decimals comma seperated | |
| 113 | 113 | m_colorStringHexaLower, ///< the current color under mouse as web RGB with lower hexadecimals | |
| 114 | 114 | m_colorStringHexaUpper; ///< the current color under mouse as web RGB with upper hexadecimals | |
| 115 | QMenu *menu, ///< The main menu of Quax | ||
| 116 | *menuZoom, ///< Menu for zoom levels and zoom in and zoom out items | ||
| 117 | *menuLook, ///< The "Look at" menu | ||
| 118 | *menuColor; ///< Menu for coying textual representation into clipboard | ||
| 115 | QMenu *m_menu, ///< The main menu of Quax | ||
| 116 | *m_menuZoom, ///< Menu for zoom levels and zoom in and zoom out items | ||
| 117 | *m_menuLook, ///< The "Look at" menu | ||
| 118 | *m_menuColor; ///< Menu for coying textual representation into clipboard | ||
| 119 | 119 | QActionGroup *m_zoomGroup, | |
| 120 | 120 | *m_rotGroup, | |
| 121 | 121 | *m_colorGroup; | |
| … | … | ||
| 126 | 126 | m_colorTipEnabled;///< if true, the color tooltip is displayed | |
| 127 | 127 | int m_zoomLevel, ///< current zoom level | |
| 128 | 128 | m_lookAt; ///< current quadrant direction where Quax "look at" | |
| 129 | QPoint dragOffset; ///< the offset between Quax position and new mouse position | ||
| 129 | QPoint m_dragOffset; ///< the offset between Quax position and new mouse position | ||
| 130 | 130 | ||
| 131 | 131 | /** | |
| 132 | 132 | * It grabs the desktop area, scale it, clip it with circle region, |

