Commit 89a3b11416b07bf66ce417102d4937ba54f864c8

Code clenaup, still compiles.
src/main.cpp
(22 / 23)
  
55// Description: main application
66//
77//
8// Author: <claudiuc@kde.org>, (C) 2001, 2002, 2003
8// Authors: <claudiuc@kde.org>, (C) 2001, 2002, 2003
9// <enrico.ros@gmail.com>, (C) 2009
910//
1011// Copyright: See COPYING file that comes with this distribution
1112//
1213//
1314
14#include <qtextcodec.h>
15#include <qtranslator.h>
16#include <qapplication.h>
15#include <QApplication>
16#include <QLocale>
17#include <QTranslator>
1718
1819#include "quax.h"
1920
21int main(int argc, char ** argv)
22{
23 QApplication app(argc, argv);
24 app.setApplicationName("Quax");
25 app.setApplicationVersion("1.2");
2026
21int main(int argc, char ** argv) {
27 // install translators (qt + this application)
28 QString locale = QLocale::system().name();
29 QTranslator qTranslator;
30 qTranslator.load(QString("qt_") + locale, ".");
31 app.installTranslator(&qTranslator);
32 QTranslator appTranslator;
33 appTranslator.load(QString("quax_") + locale, ".");
34 app.installTranslator(&appTranslator);
2235
23 QApplication a(argc,argv);
24
25 // translation file for Qt
26 QTranslator qt(0);
27 qt.load(QString("qt_")+QTextCodec::locale(),".");
28 a.installTranslator(&qt);
29
30 // translation file for my application
31 QTranslator myapp(0);
32 qt.load(QString("quax_")+QTextCodec::locale(),".");
33 a.installTranslator(&myapp);
34
35 Quax * quax = new Quax();
36
37 a.setMainWidget(quax);
38 quax->setCaption("Quax");
39 quax->show();
40 return a.exec();
36 Quax quax;
37 quax.setWindowTitle(app.applicationName());
38 quax.show();
39 return app.exec();
4140}
src/quax.cpp
(159 / 159)
  
4646#include <QLabel>
4747#include <QPixmap>
4848#include <Q3Frame>
49#include <Q3PopupMenu>
49#include <QMenu>
5050#include <QMouseEvent>
5151#include <QEvent>
5252#include <QPaintEvent>
6464#else
6565 // "borrowed" from kcursor.cpp from kdelibs
6666 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 };
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 };
7474 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);
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);
8383 QBitmap hand_mask(22, 22, HAND_MASK_BITS, true);
8484 hand_cursor = QCursor(hand_bitmap, hand_mask, 7, 0);
8585#endif
127127
128128
129129 // build RMB popup menu
130 menu = new Q3PopupMenu(this);
130 menu = new QMenu(this);
131131
132 menuzoom = new Q3PopupMenu(this);
132 menuzoom = new QMenu(this);
133133 menuzoom->setCheckable(true);
134134 for (int i=ZOOM_SCALE_MIN; i<=ZOOM_SCALE_MAX; i++) {
135135 zoomid[i]=menuzoom->insertItem(QObject::tr("1:%1").arg(i),this,SLOT(zoomTo(int)));
143143 menuzoom->insertItem(QPixmap(viewmagout_xpm),QObject::tr("Zoom Out"),this,SLOT(zoomOut()),Q3Accel::stringToKey(QObject::tr("-","Zoom Out")));
144144#endif
145145
146 menulook = new Q3PopupMenu(this);
146 menulook = new QMenu(this);
147147 menulook->setCheckable(true);
148148#if QT_VERSION >= 300
149149 lookid[1]=menulook->insertItem(QObject::tr("North-West"),this,SLOT(rotateNorthWest()),QKeySequence(QObject::tr("U","North-West")));
164164 menulook->insertItem(QPixmap(left_xpm),QObject::tr("Rotate Left"),this,SLOT(rotateLeft()),Q3Accel::stringToKey(QObject::tr("l","Rotate Left")));
165165 menulook->insertItem(QPixmap(right_xpm),QObject::tr("Rotate Right"),this,SLOT(rotateRight()),Q3Accel::stringToKey(QObject::tr("r","Rotate Right")));
166166#endif
167
168 menucolor = new Q3PopupMenu(this);
167
168 menucolor = new QMenu(this);
169169 colorid[1]=menucolor->insertItem(colorStringDecimal,this,SLOT(copyColor(int)));
170170#if QT_VERSION >= 300
171171 colorid[2]=menucolor->insertItem(colorStringHexaLower,this,SLOT(copyColor(int)),QKeySequence(QObject::tr("Ctrl+C","Copy Color")));
219219
220220
221221Quax::~Quax() {
222 delete colorTip;
222 delete colorTip;
223223}
224224
225225
226226void Quax::enterEvent(QEvent *e) {
227 e=e;
227 e=e;
228228
229 cursorOverQuax=true;
230 if (colorTipShowed && colorTip->isHidden()) {
231 displayColorTip();
232 }
229 cursorOverQuax=true;
230 if (colorTipShowed && colorTip->isHidden()) {
231 displayColorTip();
232 }
233233}
234234
235235
236236void Quax::leaveEvent(QEvent *e) {
237 e=e;
237 e=e;
238238
239 cursorOverQuax=false;
240 if (colorTipShowed) {
241 colorTip->hide();
242 }
239 cursorOverQuax=false;
240 if (colorTipShowed) {
241 colorTip->hide();
242 }
243243}
244244
245245
277277}
278278
279279void Quax::wheelEvent(QWheelEvent *e) {
280 if (ctrlKeyOn) {
281 if (e->delta()>0) {
282 rotateLeft();
280 if (ctrlKeyOn) {
281 if (e->delta()>0) {
282 rotateLeft();
283 } else {
284 rotateRight();
285 }
283286 } else {
284 rotateRight();
287 if (e->delta()>0) {
288 zoomIn();
289 } else {
290 zoomOut();
291 }
285292 }
286 } else {
287 if (e->delta()>0) {
288 zoomIn();
289 } else {
290 zoomOut();
293 e->accept();
294 if (colorTipShowed && ! colorTip->isHidden()) {
295 displayColorTip();
291296 }
292 }
293 e->accept();
294 if (colorTipShowed && ! colorTip->isHidden()) {
295 displayColorTip();
296 }
297297}
298298
299299void Quax::grab() {
371371}
372372
373373void Quax::grabForPixel() {
374 // get the color under cursor
375 QPixmap pix_grab = QPixmap::grabWindow(QApplication::desktop()->winId(),QCursor::pos().x()-1,QCursor::pos().y()-1,1,1);
376 QImage img_grab = pix_grab.convertToImage();
377 QRgb rgb_color = img_grab.pixel(0,0);
378 colorStringDecimal = QString::number(qRed(rgb_color)) + ", " +
379 QString::number(qGreen(rgb_color)) + ", " +
380 QString::number(qBlue(rgb_color));
381 colorStringHexaLower.sprintf("#%02x%02x%02x",qRed(rgb_color),qGreen(rgb_color),qBlue(rgb_color));
382 colorStringHexaUpper = colorStringHexaLower.upper();
374 // get the color under cursor
375 QPixmap pix_grab = QPixmap::grabWindow(QApplication::desktop()->winId(),QCursor::pos().x()-1,QCursor::pos().y()-1,1,1);
376 QImage img_grab = pix_grab.convertToImage();
377 QRgb rgb_color = img_grab.pixel(0,0);
378 colorStringDecimal = QString::number(qRed(rgb_color)) + ", " +
379 QString::number(qGreen(rgb_color)) + ", " +
380 QString::number(qBlue(rgb_color));
381 colorStringHexaLower.sprintf("#%02x%02x%02x",qRed(rgb_color),qGreen(rgb_color),qBlue(rgb_color));
382 colorStringHexaUpper = colorStringHexaLower.upper();
383383
384 // make a little pixmap with grabbed color
385 QMatrix m;
386 m.scale((double)14,(double)14);
387 pix_cursor=pix_grab.xForm(m);
384 // make a little pixmap with grabbed color
385 QMatrix m;
386 m.scale((double)14,(double)14);
387 pix_cursor=pix_grab.xForm(m);
388388}
389389
390390void Quax::displayColorTip() {
391return;
392/*
391 return;
392 /*
393393 grabForPixel();
394394 Q3MimeSourceFactory::defaultFactory()->setPixmap("pixel",pix_cursor);
395395 colorTip->setText("<qml>&nbsp;<img height=\"14\" width=\"14\" src=\"pixel\">&nbsp;<tt>" + colorStringHexaUpper + "</tt></qml>");
420420 switch (e->button()) {
421421 case Qt::LeftButton:
422422 if (colorTipShowed) {
423 copyColor(0);
424 setCursor(copy_cursor);
423 copyColor(0);
424 setCursor(copy_cursor);
425425 } else {
426 grabMouse(hand_cursor);
427 inDrag=true;
428 dragOffset = QCursor::pos() - QPoint(geometry().left(),geometry().top());
426 grabMouse(hand_cursor);
427 inDrag=true;
428 dragOffset = QCursor::pos() - QPoint(geometry().left(),geometry().top());
429429 }
430430 break;
431431 case Qt::RightButton:
440440 switch (e->button()) {
441441 case Qt::LeftButton:
442442 if (colorTipShowed) {
443 setCursor(cross_cursor);
443 setCursor(cross_cursor);
444444 } else {
445 releaseMouse();
446 inDrag=false;
445 releaseMouse();
446 inDrag=false;
447447 }
448448 break;
449449 default:
455455 e=e;
456456
457457 if (colorTipShowed && cursorOverQuax) {
458 displayColorTip();
458 displayColorTip();
459459 }
460460 if (!inDrag || this != mouseGrabber()) return;
461461 move(QCursor::pos()-dragOffset);
464464
465465void Quax::keyReleaseEvent(QKeyEvent *e) {
466466 if (ctrlKeyOn) {
467 if (!(e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control)) {
468 ctrlKeyOn=false;
469 }
467 if (!(e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control)) {
468 ctrlKeyOn=false;
469 }
470470 }
471471
472472 if (colorTipShowed) {
473 if (e->key() == Qt::Key_Control ||e->key() == Qt::Key_Shift) {
474 colorTipShowed=false;
475 setCursor(hand_cursor);
476 colorTip->hide();
477 }
473 if (e->key() == Qt::Key_Control ||e->key() == Qt::Key_Shift) {
474 colorTipShowed=false;
475 setCursor(hand_cursor);
476 colorTip->hide();
477 }
478478 }
479479}
480480
482482 QPoint dist(0,0);
483483
484484 if (!(e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control)) {
485 ctrlKeyOn=true;
486 e->ignore();
487 return;
485 ctrlKeyOn=true;
486 e->ignore();
487 return;
488488 }
489489
490490 if (!colorTipShowed) {
491 if ((e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control) ||
492 (e->state() & Qt::ControlButton) && (e->key() == Qt::Key_Shift)) {
493 colorTipShowed=true;
494 ctrlKeyOn=false;
495 setCursor(cross_cursor);
496 displayColorTip();
497 e->ignore();
498 return;
499 }
491 if (((e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control)) ||
492 ((e->state() & Qt::ControlButton) && (e->key() == Qt::Key_Shift))) {
493 colorTipShowed=true;
494 ctrlKeyOn=false;
495 setCursor(cross_cursor);
496 displayColorTip();
497 e->ignore();
498 return;
499 }
500500 }
501501
502502
503503
504504 switch (e->key()) {
505 case Qt::Key_Left:
505 case Qt::Key_Left:
506506 dist.setX(-1);
507 break;
508 case Qt::Key_Right:
507 break;
508 case Qt::Key_Right:
509509 dist.setX(1);
510 break;
511 case Qt::Key_Up:
510 break;
511 case Qt::Key_Up:
512512 dist.setY(-1);
513 break;
514 case Qt::Key_Down:
513 break;
514 case Qt::Key_Down:
515515 dist.setY(1);
516 break;
517 case Qt::Key_Equal:
518 zoomIn();
519 break;
520 case Qt::Key_Underscore:
521 zoomOut();
522 break;
523 default:
516 break;
517 case Qt::Key_Equal:
518 zoomIn();
519 break;
520 case Qt::Key_Underscore:
521 zoomOut();
522 break;
523 default:
524524 e->ignore();
525525 return;
526526 }
534534#if QT_VERSION >= 300
535535#ifdef _OS_WIN32_
536536#else
537 QString helpApp = "kfmclient";
537 QString helpApp = "kfmclient";
538538
539 Q3Process *proc = new Q3Process(this);
540 proc->addArgument(helpApp);
541 proc->addArgument("openURL");
542 proc->addArgument("help:quax");
543 proc->closeStdin();
544 if (!proc->start()) {
545 QMessageBox::critical(this,QObject::tr("Help Error"),
546 QObject::tr("<qml>There was an error executing <b>%1</b> application. "
547 "Please check your KDE installation. You may try to open an <b>xterm</b> "
548 "window and run <tt>man quax</tt> from there.</qml>").arg(helpApp),
549 QMessageBox::Ok, Qt::NoButton, Qt::NoButton);
550 }
539 Q3Process *proc = new Q3Process(this);
540 proc->addArgument(helpApp);
541 proc->addArgument("openURL");
542 proc->addArgument("help:quax");
543 proc->closeStdin();
544 if (!proc->start()) {
545 QMessageBox::critical(this,QObject::tr("Help Error"),
546 QObject::tr("<qml>There was an error executing <b>%1</b> application. "
547 "Please check your KDE installation. You may try to open an <b>xterm</b> "
548 "window and run <tt>man quax</tt> from there.</qml>").arg(helpApp),
549 QMessageBox::Ok, Qt::NoButton, Qt::NoButton);
550 }
551551#endif
552552#endif
553553}
554554
555555void Quax::about() {
556 QMessageBox::about(this,QObject::tr("About Quax %1").arg(VERSION "-" RELEASE),QObject::tr(
557 "<p><b>Quax</b> is a little magnifing tool for X. Quax homepage is "
558 "at <tt>&lt;http://www.ro.kde.org/quax/&gt;</tt>."
559 "</p><p>This is Quax version %1."
560 "</p><p>This program is released under GNU General Public License."
561 "<dl>"
562 "<dt><nobr>Claudiu Costin <tt>&lt;claudiuc@kde.org&gt;</tt></nobr></dt>"
563 "<dd>coding, documentation, packaging</dd>"
564 "<dt><nobr>Vlad Oancea <tt>&lt;xtrim@fx.ro&gt;</tt></nobr></dt>"
565 "<dd>Quax skin design</dd>"
566 "</dl></p>").arg(VERSION "-" RELEASE));
556 QMessageBox::about(this,QObject::tr("About Quax %1").arg(QUAX_VERSION "-" QUAX_RELEASE),QObject::tr(
557 "<p><b>Quax</b> is a little magnifing tool for X. Quax homepage is "
558 "at <tt>&lt;http://www.ro.kde.org/quax/&gt;</tt>."
559 "</p><p>This is Quax version %1."
560 "</p><p>This program is released under GNU General Public License."
561 "<dl>"
562 "<dt><nobr>Claudiu Costin <tt>&lt;claudiuc@kde.org&gt;</tt></nobr></dt>"
563 "<dd>coding, documentation, packaging</dd>"
564 "<dt><nobr>Vlad Oancea <tt>&lt;xtrim@fx.ro&gt;</tt></nobr></dt>"
565 "<dd>Quax skin design</dd>"
566 "</dl></p>").arg(QUAX_VERSION "-" QUAX_RELEASE));
567567}
568568
569569void Quax::aboutQt() {
589589void Quax::zoomTo(int pos) {
590590 for (int i=ZOOM_SCALE_MIN;i<=ZOOM_SCALE_MAX;i++)
591591 if (zoomid[i]==pos) {
592 menuzoom->setItemChecked(zoomid[i],true);
593 zoom=i;
594 } else {
595 menuzoom->setItemChecked(zoomid[i],false);
596 }
592 menuzoom->setItemChecked(zoomid[i],true);
593 zoom=i;
594 } else {
595 menuzoom->setItemChecked(zoomid[i],false);
596 }
597597}
598598
599599void Quax::rotateNorthWest() {
655655
656656
657657void Quax::copyColor(int id) {
658
659 if (id == colorid[1] ) {
660 qApp->clipboard()->setText(colorStringDecimal);
661 } else if (id == colorid[2]) {
662 // this get called when user press Ctrl+C
663 //
664 // I must call grabForPixel because it's posible that
665 // this slot get executed even user doesn't right click
666 // on Quax, so updateMenuColor is not yet called and
667 // variables may contain old or invalid color
668 grabForPixel();
669 qApp->clipboard()->setText(colorStringHexaLower);
670 } else if (id == colorid[3] || id == 0) {
671 // id=0 if user click when color tip is displayed
672 qApp->clipboard()->setText(colorStringHexaUpper);
673 } else {
674 qWarning("id=%d: This must not happen",id);
675 }
658
659 if (id == colorid[1] ) {
660 qApp->clipboard()->setText(colorStringDecimal);
661 } else if (id == colorid[2]) {
662 // this get called when user press Ctrl+C
663 //
664 // I must call grabForPixel because it's posible that
665 // this slot get executed even user doesn't right click
666 // on Quax, so updateMenuColor is not yet called and
667 // variables may contain old or invalid color
668 grabForPixel();
669 qApp->clipboard()->setText(colorStringHexaLower);
670 } else if (id == colorid[3] || id == 0) {
671 // id=0 if user click when color tip is displayed
672 qApp->clipboard()->setText(colorStringHexaUpper);
673 } else {
674 qWarning("id=%d: This must not happen",id);
675 }
676676}
677677
678678void Quax::updateMenuColor() {
679 grabForPixel();
679 grabForPixel();
680680#if QT_VERSION > 300
681 ///pixelColorIcon->clearGenerated();
681 ///pixelColorIcon->clearGenerated();
682682#endif
683 pixelColorIcon->reset(pix_cursor,QIcon::Small);
683 pixelColorIcon->reset(pix_cursor,QIcon::Small);
684684
685 menu->changeItem(colorid[0],QIcon(pix_cursor),QObject::tr("Copy Color"));
686 menucolor->changeItem(colorid[1],colorStringDecimal);
687 menucolor->changeItem(colorid[2],colorStringHexaLower);
688 menucolor->changeItem(colorid[3],colorStringHexaUpper);
685 menu->changeItem(colorid[0],QIcon(pix_cursor),QObject::tr("Copy Color"));
686 menucolor->changeItem(colorid[1],colorStringDecimal);
687 menucolor->changeItem(colorid[2],colorStringHexaLower);
688 menucolor->changeItem(colorid[3],colorStringHexaUpper);
689689}
src/quax.h
(183 / 184)
  
55// Description: Quax declarations
66//
77//
8// Author: <claudiuc@kde.org>, (C) 2001, 2002, 2003
8// Authors: <claudiuc@kde.org>, (C) 2001, 2002, 2003
9// <enrico.ros@gmail.com>, (C) 2009
910//
1011// Copyright: See COPYING file that comes with this distribution
1112//
1213//
1314
14#ifndef QUAX_H
15#define QUAX_H
15#ifndef __quax_h__
16#define __quax_h__
1617
17#include "../config.h"
18
1918#include <qglobal.h>
2019
2120#include <qcursor.h>
3030#include <qmessagebox.h>
3131#include <qapplication.h>
3232#include <qmatrix.h>
33#include <q3popupmenu.h>
3433#include <qapplication.h>
3534//Added by qt3to4:
35#include <QMenu>
3636#include <QWheelEvent>
3737#include <QEvent>
3838#include <QMouseEvent>
4040#include <QKeyEvent>
4141#include <QPaintEvent>
4242
43#define QUAX_VERSION "1.0"
44#define QUAX_RELEASE "1"
45
4346#define PIX_CURSOR_SCALE 10
4447#define ZOOM_SCALE_MIN 2
4548#define ZOOM_SCALE_MAX 5
5656
5757#define UPDATE 40
5858
59
6059/**
6160 * Magnifing widget for desktop
6261 *
6565 */
6666class Quax : public QWidget
6767{
68 Q_OBJECT
68 Q_OBJECT
69 public:
70 /**
71 * Contruct Quax GUI and initialize variables to sane values.
72 * It build popup menu, set the Quax widget pixmap mask, build custom
73 * cursors and start grab timer.
74 */
75 Quax();
76 /**
77 * Destroy Quax instance
78 */
79 ~Quax();
80
81 protected:
82 /**
83 * Show color tooltip when mouse enter Quax area, and set
84 * the @p cursorOverQuax flag.
85 */
86 void enterEvent(QEvent *e);
87 /**
88 * Hide color tooltip if shown, and set the @p cursorOverQuax flag.
89 */
90 void leaveEvent(QEvent *e);
91 /**
92 * If right button was pressed, show popup menu. If color tooltip is already
93 * showed then "take a shot" of current pixel under cursor.
94 */
95 void mousePressEvent(QMouseEvent *e);
96 /**
97 * Executed when user release one mouse button.
98 */
99 void mouseReleaseEvent(QMouseEvent *e);
100 /**
101 * Executed when user release move the mouse. If the color tip is enabled,
102 * then displayed color is updated as well the tooltip position.
103 * If is @p inDrag is true, then Quax position is updated (dragged)
104 * to that of mouse position.
105 */
106 void mouseMoveEvent(QMouseEvent *e);
107 /**
108 * Get the modifier keys status and display color tooltip if Shift and Ctrl
109 * are both pressed down. If cursor keys are pressed, then adjust Quax
110 * position by one pixel or by ten pixels if Shift is down.
111 */
112 void keyPressEvent(QKeyEvent *e);
113 /**
114 * Hide color tooltip if one of Shift and Ctrl key modifiers is released.
115 */
116 void keyReleaseEvent(QKeyEvent *e);
117 /**
118 * Take the grabbed @p pix_zoom pixmap and scale it. Then it's painted
119 * on Quax following an circle region for clipping.
120 */
121 void paintEvent(QPaintEvent *e);
122 /**
123 * Grab a screen region at every 40 miliseconds executing @ref grab().
124 */
125 void timerEvent(QTimerEvent *e);
126 /**
127 * If mouse wheel is dragged, then zoom scale in or out. When Ctrl key
128 * modifier is pressed, Quax is rotated left or right
129 */
130 void wheelEvent(QWheelEvent *e);
69131
70public:
71 /**
72 * Contruct Quax GUI and initialize variables to sane values.
73 * It build popup menu, set the Quax widget pixmap mask, build custom
74 * cursors and start grab timer.
75 */
76 Quax();
77 /**
78 * Destroy Quax instance
79 */
80 ~Quax();
132 private:
133 QString colorStringDecimal, ///< the current color under mouse as decimals comma seperated
134 colorStringHexaLower, ///< the current color under mouse as web RGB with lower hexadecimals
135 colorStringHexaUpper; ///< the current color under mouse as web RGB with upper hexadecimals
136 QIcon *pixelColorIcon; ///< The icon set which is used in QML content from @ref colorTip
137 QLabel *colorTip; ///< The tool tip for displaying current color under mouse
138 QMenu *menu, ///< The main menu of Quax
139 *menuzoom, ///< Menu for zoom levels and zoom in and zoom out items
140 *menulook, ///< The "Look at" menu
141 *menucolor; ///< Menu for coying textual representation into clipboard
142 QPixmap pix, ///< Quax skin image
143 pix_alpha, ///< Quax alpha mask for skin image
144 pix_zoom, ///< The grabbed image zoomend and clipped
145 pix_cursor; ///< The icon used in color menu item and color tooltip
146 QCursor hand_cursor, ///< normal mouse cursor when mouse pointer is over Quax
147 cross_cursor, ///< cursor when color tooltip is displayed (cross)
148 copy_cursor; ///< cursor when user "take a shot" of current color
149 bool inDrag, ///< if true, the user is dragging the Quax
150 colorTipShowed, ///< if true, the color tooltip is displayed
151 cursorOverQuax, ///< if true, mouse cursor is over Quax surface
152 ctrlKeyOn; ///< if true, the Ctrl key is pressed down
153 QPoint dragOffset; ///< the offset between Quax position and new mouse position
154 QMap<int,int> zoomid, ///< mapping between zoom level and @ref menuzoom menu item ids
155 lookid, ///< mapping between look direction and @ref menulook menu item ids
156 colorid; ///< mapping between text color type and @ref menucolor menu item ids
157 int zoom, ///< current zoom level
158 look; ///< current quadrant direction where Quax "look at"
81159
82protected:
83 /**
84 * Show color tooltip when mouse enter Quax area, and set
85 * the @p cursorOverQuax flag.
86 */
87 void enterEvent(QEvent *e);
88 /**
89 * Hide color tooltip if shown, and set the @p cursorOverQuax flag.
90 */
91 void leaveEvent(QEvent *e);
92 /**
93 * If right button was pressed, show popup menu. If color tooltip is already
94 * showed then "take a shot" of current pixel under cursor.
95 */
96 void mousePressEvent(QMouseEvent *e);
97 /**
98 * Executed when user release one mouse button.
99 */
100 void mouseReleaseEvent(QMouseEvent *e);
101 /**
102 * Executed when user release move the mouse. If the color tip is enabled,
103 * then displayed color is updated as well the tooltip position.
104 * If is @p inDrag is true, then Quax position is updated (dragged)
105 * to that of mouse position.
106 */
107 void mouseMoveEvent(QMouseEvent *e);
108 /**
109 * Get the modifier keys status and display color tooltip if Shift and Ctrl
110 * are both pressed down. If cursor keys are pressed, then adjust Quax
111 * position by one pixel or by ten pixels if Shift is down.
112 */
113 void keyPressEvent(QKeyEvent *e);
114 /**
115 * Hide color tooltip if one of Shift and Ctrl key modifiers is released.
116 */
117 void keyReleaseEvent(QKeyEvent *e);
118 /**
119 * Take the grabbed @p pix_zoom pixmap and scale it. Then it's painted
120 * on Quax following an circle region for clipping.
121 */
122 void paintEvent(QPaintEvent *e);
123 /**
124 * Grab a screen region at every 40 miliseconds executing @ref grab().
125 */
126 void timerEvent(QTimerEvent *e);
127 /**
128 * If mouse wheel is dragged, then zoom scale in or out. When Ctrl key
129 * modifier is pressed, Quax is rotated left or right
130 */
131 void wheelEvent(QWheelEvent *e);
132
133private:
134 QString colorStringDecimal, ///< the current color under mouse as decimals comma seperated
135 colorStringHexaLower, ///< the current color under mouse as web RGB with lower hexadecimals
136 colorStringHexaUpper; ///< the current color under mouse as web RGB with upper hexadecimals
137 QIcon *pixelColorIcon; ///< The icon set which is used in QML content from @ref colorTip
138 QLabel *colorTip; ///< The tool tip for displaying current color under mouse
139 Q3PopupMenu *menu, ///< The main menu of Quax
140 *menuzoom, ///< Menu for zoom levels and zoom in and zoom out items
141 *menulook, ///< The "Look at" menu
142 *menucolor; ///< Menu for coying textual representation into clipboard
143 QPixmap pix, ///< Quax skin image
144 pix_alpha, ///< Quax alpha mask for skin image
145 pix_zoom, ///< The grabbed image zoomend and clipped
146 pix_cursor; ///< The icon used in color menu item and color tooltip
147 QCursor hand_cursor, ///< normal mouse cursor when mouse pointer is over Quax
148 cross_cursor, ///< cursor when color tooltip is displayed (cross)
149 copy_cursor; ///< cursor when user "take a shot" of current color
150 bool inDrag, ///< if true, the user is dragging the Quax
151 colorTipShowed, ///< if true, the color tooltip is displayed
152 cursorOverQuax, ///< if true, mouse cursor is over Quax surface
153 ctrlKeyOn; ///< if true, the Ctrl key is pressed down
154 QPoint dragOffset; ///< the offset between Quax position and new mouse position
155 QMap<int,int> zoomid, ///< mapping between zoom level and @ref menuzoom menu item ids
156 lookid, ///< mapping between look direction and @ref menulook menu item ids
157 colorid; ///< mapping between text color type and @ref menucolor menu item ids
158 int zoom, ///< current zoom level
159 look; ///< current quadrant direction where Quax "look at"
160 /**
161 * It grab desktop area, scale it, clip it with circle region,
162 * and then paint on Quax area.
163 */
164 void grab();
165 /**
166 * Show color tooltip and move the QLabel when mouse position change. Color
167 * is updated runnning @ref grabForPixel(). If tooltip will be displayed
168 * clipped by screen margins, then it will be repositioned before moving.
169 */
170 void displayColorTip();
171 /**
172 * Grab exactly one pixel under mouse cursor to show it in color tooltip.
173 */
174 void grabForPixel();
160175
161 /**
162 * It grab desktop area, scale it, clip it with circle region,
163 * and then paint on Quax area.
164 */
165 void grab();
166 /**
167 * Show color tooltip and move the QLabel when mouse position change. Color
168 * is updated runnning @ref grabForPixel(). If tooltip will be displayed
169 * clipped by screen margins, then it will be repositioned before moving.
170 */
171 void displayColorTip();
172 /**
173 * Grab exactly one pixel under mouse cursor to show it in color tooltip.
174 */
175 void grabForPixel();
176
177protected slots:
178 /**
179 * Display manual page or open help center according with underling desktop environment.
180 */
181 void help();
182 /**
183 * Open Quax "about" messagebox with author list and some other
184 * usefull information (copyright, version).
185 */
186 void about();
187 /**
188 * Open Trolltech standard "about" messagebox.
189 */
190 void aboutQt();
191 /**
192 * Scale up grabed desktop area if not at maximum zoom value.
193 */
194 void zoomIn();
195 /**
196 * Scale down grabed desktop area if not at minimum zoom value.
197 */
198 void zoomOut();
199 /**
200 * Zoom grabed desktop area to the @p pos level.
201 * @param pos represent position into zoom menu, as well the zoom level
202 */
203 void zoomTo(int pos);
204 /**
205 * Move the Quax point of desktop area grab to the North-West direction.
206 * It make use of @ref Quax::rotate
207 */
208 void rotateNorthWest();
209 /**
210 * Move the Quax point of desktop area grab to the South-West direction.
211 */
212 void rotateSouthWest();
213 /**
214 * Move the Quax point of desktop area grab to the North-East direction.
215 */
216 void rotateNorthEast();
217 /**
218 * Move the Quax point of desktop area grab to the South-East direction.
219 */
220 void rotateSouthEast();
221 /**
222 * Rotate Quax point of desktop area grab to the left (counter-clockwise).
223 */
224 void rotateLeft();
225 /**
226 * Rotate Quax point of desktop area grab to the right (clockwise).
227 */
228 void rotateRight();
229 /**
230 * Rotate Quax point of desktop area to the @p pos quadrant.
231 * @param pos quadrant number (0..3)
232 */
233 void rotate(int pos);
234 /**
235 * Copy the last color under mouse which was saved on @p colorStringDecimal,
236 * @p colorStringHexaLower and @p colorStringHexaUpper into system
237 * clipboard. For the menu item which handle "Ctrl+C" accelerator, it call
238 * @ref grabForPixel() prior to cliboard operation.
239 * @param id the menu identificator to get what color menu item was selected
240 */
241 void copyColor(int id);
242 /**
243 * Build the menu left pixmap from the grabed color under mouse. This is slot is
244 * called from QPopupMenu::aboutToShow signal.
245 */
246 void updateMenuColor();
176 protected Q_SLOTS:
177 /**
178 * Display manual page or open help center according with underling desktop environment.
179 */
180 void help();
181 /**
182 * Open Quax "about" messagebox with author list and some other
183 * usefull information (copyright, version).
184 */
185 void about();
186 /**
187 * Open Trolltech standard "about" messagebox.
188 */
189 void aboutQt();
190 /**
191 * Scale up grabed desktop area if not at maximum zoom value.
192 */
193 void zoomIn();
194 /**
195 * Scale down grabed desktop area if not at minimum zoom value.
196 */
197 void zoomOut();
198 /**
199 * Zoom grabed desktop area to the @p pos level.
200 * @param pos represent position into zoom menu, as well the zoom level
201 */
202 void zoomTo(int pos);
203 /**
204 * Move the Quax point of desktop area grab to the North-West direction.
205 * It make use of @ref Quax::rotate
206 */
207 void rotateNorthWest();
208 /**
209 * Move the Quax point of desktop area grab to the South-West direction.
210 */
211 void rotateSouthWest();
212 /**
213 * Move the Quax point of desktop area grab to the North-East direction.
214 */
215 void rotateNorthEast();
216 /**
217 * Move the Quax point of desktop area grab to the South-East direction.
218 */
219 void rotateSouthEast();
220 /**
221 * Rotate Quax point of desktop area grab to the left (counter-clockwise).
222 */
223 void rotateLeft();
224 /**
225 * Rotate Quax point of desktop area grab to the right (clockwise).
226 */
227 void rotateRight();
228 /**
229 * Rotate Quax point of desktop area to the @p pos quadrant.
230 * @param pos quadrant number (0..3)
231 */
232 void rotate(int pos);
233 /**
234 * Copy the last color under mouse which was saved on @p colorStringDecimal,
235 * @p colorStringHexaLower and @p colorStringHexaUpper into system
236 * clipboard. For the menu item which handle "Ctrl+C" accelerator, it call
237 * @ref grabForPixel() prior to cliboard operation.
238 * @param id the menu identificator to get what color menu item was selected
239 */
240 void copyColor(int id);
241 /**
242 * Build the menu left pixmap from the grabed color under mouse. This is slot is
243 * called from QPopupMenu::aboutToShow signal.
244 */
245 void updateMenuColor();
247246};
248
249247
250248#endif
src/quax.pro
(1 / 1)
  
2323 help.xpm
2424SOURCES += main.cpp quax.cpp
2525#The following line was inserted by qt3to4
26QT += qt3support
26QT += qt3support

Comments

Add a new comment:

Login or create an account to post a comment

Add your comment