Commit a8b1b71fda01a7c5be8f6cd51b60f586cdf0c44b
- Diff rendering mode:
- inline
- side by side
src/quax.cpp
(293 / 400)
|   | |||
| 5 | 5 | // Description: Quax application implementation | |
| 6 | 6 | // | |
| 7 | 7 | // | |
| 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 | ||
| 9 | 10 | // | |
| 10 | 11 | // Copyright: See COPYING file that comes with this distribution | |
| 11 | 12 | // | |
| … | … | ||
| 24 | 24 | #include "icon.xpm" | |
| 25 | 25 | #include "help.xpm" | |
| 26 | 26 | ||
| 27 | #include <qglobal.h> | ||
| 28 | |||
| 29 | #if QT_VERSION >= 300 | ||
| 30 | #include <q3process.h> | ||
| 31 | #else | ||
| 32 | #include <qmatrix.h> | ||
| 33 | #include <qbitmap.h> | ||
| 34 | #include <q3accel.h> | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #include <qtooltip.h> | ||
| 38 | #include <qcolor.h> | ||
| 39 | #include <qcursor.h> | ||
| 40 | #include <qclipboard.h> | ||
| 41 | |||
| 42 | |||
| 43 | 27 | #include "quax.h" | |
| 44 | //Added by qt3to4: | ||
| 28 | |||
| 29 | #include <QToolTip> | ||
| 30 | #include <QColor> | ||
| 31 | #include <QCursor> | ||
| 32 | #include <QClipboard> | ||
| 33 | #include <QProcess> | ||
| 34 | #include <QDesktopServices> | ||
| 35 | #include <QUrl> | ||
| 45 | 36 | #include <QTimerEvent> | |
| 46 | 37 | #include <QKeyEvent> | |
| 47 | 38 | #include <QLabel> | |
| 48 | 39 | #include <QPixmap> | |
| 49 | #include <Q3Frame> | ||
| 50 | 40 | #include <QMenu> | |
| 51 | 41 | #include <QMouseEvent> | |
| 52 | 42 | #include <QEvent> | |
| … | … | ||
| 50 | 50 | , m_colorStringDecimal("255, 255, 255") | |
| 51 | 51 | , m_colorStringHexaLower("#ffffff") | |
| 52 | 52 | , m_colorStringHexaUpper("#FFFFFF") | |
| 53 | , m_pixelColorIcon(new QIcon) | ||
| 54 | 53 | , m_inDrag(false) | |
| 55 | , m_colorTipShowed(false) | ||
| 56 | , m_cursorOverQuax(false) | ||
| 57 | , m_ctrlKeyOn(false) | ||
| 54 | , m_colorTipEnabled(false) | ||
| 58 | 55 | , m_zoom(ZOOM_SCALE_MIN) | |
| 59 | 56 | , m_lookAt(0) | |
| 60 | 57 | { | |
| … | … | ||
| 60 | 60 | setFixedSize(150, 150); | |
| 61 | 61 | setCursor(Qt::PointingHandCursor); | |
| 62 | 62 | setIcon(QPixmap(icon_xpm)); | |
| 63 | |||
| 64 | // set the background image and shape | ||
| 65 | pix = QPixmap(mag_xpm); | ||
| 66 | QPalette pal; | ||
| 67 | pal.setBrush(QPalette::Window, pix); | ||
| 68 | setAutoFillBackground(true); | ||
| 69 | setPalette(pal); | ||
| 70 | pix_alpha = QPixmap(mag_alpha_xpm); | ||
| 71 | setMask(pix_alpha.mask()); | ||
| 72 | |||
| 73 | pix_cursor.resize(14,14); | ||
| 63 | rotate(0); | ||
| 74 | 64 | ||
| 75 | 65 | // build RMB popup menu | |
| 76 | 66 | menu = new QMenu(this); | |
| … | … | ||
| 69 | 69 | for (int i = ZOOM_SCALE_MIN; i <= ZOOM_SCALE_MAX; i++) | |
| 70 | 70 | zoomid[i]=menuZoom->insertItem(tr("1:%1").arg(i), this, SLOT(zoomTo(int))); | |
| 71 | 71 | menuZoom->addSeparator(); | |
| 72 | #if QT_VERSION >= 300 | ||
| 73 | menuZoom->insertItem(QPixmap(viewmagin_xpm),QObject::tr("Zoom In"),this,SLOT(zoomIn()),QKeySequence(QObject::tr("+","Zoom In"))); | ||
| 74 | menuZoom->insertItem(QPixmap(viewmagout_xpm),QObject::tr("Zoom Out"),this,SLOT(zoomOut()),QKeySequence(QObject::tr("-","Zoom Out"))); | ||
| 75 | #else | ||
| 76 | menuZoom->insertItem(QPixmap(viewmagin_xpm),QObject::tr("Zoom In"),this,SLOT(zoomIn()),Q3Accel::stringToKey(QObject::tr("+","Zoom In"))); | ||
| 77 | menuZoom->insertItem(QPixmap(viewmagout_xpm),QObject::tr("Zoom Out"),this,SLOT(zoomOut()),Q3Accel::stringToKey(QObject::tr("-","Zoom Out"))); | ||
| 78 | #endif | ||
| 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"))); | ||
| 79 | 74 | ||
| 80 | 75 | menuLook = new QMenu(this); | |
| 81 | 76 | menuLook->setCheckable(true); | |
| 82 | #if QT_VERSION >= 300 | ||
| 83 | lookid[1]=menuLook->insertItem(QObject::tr("North-West"),this,SLOT(rotateNorthWest()),QKeySequence(QObject::tr("U","North-West"))); | ||
| 84 | lookid[0]=menuLook->insertItem(QObject::tr("South-West"),this,SLOT(rotateSouthWest()),QKeySequence(QObject::tr("J","South-West"))); | ||
| 85 | lookid[2]=menuLook->insertItem(QObject::tr("North-East"),this,SLOT(rotateNorthEast()),QKeySequence(QObject::tr("I","North-East"))); | ||
| 86 | lookid[3]=menuLook->insertItem(QObject::tr("South-East"),this,SLOT(rotateSouthEast()),QKeySequence(QObject::tr("K","South-East"))); | ||
| 87 | #else | ||
| 88 | lookid[1]=menuLook->insertItem(QObject::tr("North-West"),this,SLOT(rotateNorthWest()),Q3Accel::stringToKey(QObject::tr("u","North-West"))); | ||
| 89 | lookid[0]=menuLook->insertItem(QObject::tr("South-West"),this,SLOT(rotateSouthWest()),Q3Accel::stringToKey(QObject::tr("j","South-West"))); | ||
| 90 | lookid[2]=menuLook->insertItem(QObject::tr("North-East"),this,SLOT(rotateNorthEast()),Q3Accel::stringToKey(QObject::tr("i","North-East"))); | ||
| 91 | lookid[3]=menuLook->insertItem(QObject::tr("South-East"),this,SLOT(rotateSouthEast()),Q3Accel::stringToKey(QObject::tr("k","South-East"))); | ||
| 92 | #endif | ||
| 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"))); | ||
| 93 | 81 | menuLook->insertSeparator(); | |
| 94 | #if QT_VERSION >= 300 | ||
| 95 | menuLook->insertItem(QPixmap(left_xpm),QObject::tr("Rotate Left"),this,SLOT(rotateLeft()),QKeySequence(QObject::tr("L","Rotate Left"))); | ||
| 96 | menuLook->insertItem(QPixmap(right_xpm),QObject::tr("Rotate Right"),this,SLOT(rotateRight()),QKeySequence(QObject::tr("R","Rotate Right"))); | ||
| 97 | #else | ||
| 98 | menuLook->insertItem(QPixmap(left_xpm),QObject::tr("Rotate Left"),this,SLOT(rotateLeft()),Q3Accel::stringToKey(QObject::tr("l","Rotate Left"))); | ||
| 99 | menuLook->insertItem(QPixmap(right_xpm),QObject::tr("Rotate Right"),this,SLOT(rotateRight()),Q3Accel::stringToKey(QObject::tr("r","Rotate Right"))); | ||
| 100 | #endif | ||
| 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"))); | ||
| 101 | 84 | ||
| 102 | 85 | menuColor = new QMenu(this); | |
| 103 | colorid[1]=menuColor->insertItem(m_colorStringDecimal,this,SLOT(copyColor(int))); | ||
| 104 | #if QT_VERSION >= 300 | ||
| 105 | colorid[2]=menuColor->insertItem(m_colorStringHexaLower,this,SLOT(copyColor(int)),QKeySequence(QObject::tr("Ctrl+C","Copy Color"))); | ||
| 106 | #else | ||
| 107 | colorid[2]=menuColor->insertItem(m_colorStringHexaLower,this,SLOT(copyColor(int)),Q3Accel::stringToKey(QObject::tr("Ctrl+c","Copy Color"))); | ||
| 108 | #endif | ||
| 109 | colorid[3]=menuColor->insertItem(m_colorStringHexaUpper,this,SLOT(copyColor(int))); | ||
| 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))); | ||
| 110 | 89 | ||
| 111 | 90 | menu->insertItem(QPixmap(viewmag_xpm),QObject::tr("Zoom"),menuZoom); | |
| 112 | menu->insertItem(QPixmap(look_xpm),QObject::tr("m_lookAt At"),menuLook); | ||
| 113 | colorid[0]=menu->insertItem(pix_cursor,QObject::tr("Copy Color"),menuColor); | ||
| 114 | #if QT_VERSION >= 300 | ||
| 115 | menu->insertItem(QPixmap(help_xpm),QObject::tr("Help"),this,SLOT(help()),QKeySequence(QObject::tr("H","Help"))); | ||
| 116 | #else | ||
| 117 | menu->insertItem(QPixmap(help_xpm),QObject::tr("Help"),this,SLOT(help()),Q3Accel::stringToKey(QObject::tr("h","Help"))); | ||
| 118 | #endif | ||
| 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"))); | ||
| 119 | 94 | menu->insertSeparator(); | |
| 120 | menu->insertItem(QObject::tr("About Quax"),this,SLOT(about())); | ||
| 121 | menu->insertItem(QObject::tr("About Qt"),this,SLOT(aboutQt())); | ||
| 95 | menu->insertItem(QObject::tr("About Quax"), this, SLOT(about())); | ||
| 96 | menu->insertItem(QObject::tr("About Qt"), this, SLOT(aboutQt())); | ||
| 122 | 97 | menu->insertSeparator(); | |
| 123 | #if QT_VERSION >= 300 | ||
| 124 | 98 | menu->insertItem(QPixmap(exit_xpm),QObject::tr("Quit"),qApp,SLOT(quit()),QKeySequence(QObject::tr("Q","Quit"))); | |
| 125 | #else | ||
| 126 | menu->insertItem(QPixmap(exit_xpm),QObject::tr("Quit"),qApp,SLOT(quit()),Q3Accel::stringToKey(QObject::tr("q","Quit"))); | ||
| 127 | #endif | ||
| 128 | 99 | ||
| 129 | 100 | menuZoom->setItemChecked(zoomid[m_zoom],true); | |
| 130 | 101 | menuLook->setItemChecked(lookid[m_lookAt],true); | |
| 131 | connect(menu,SIGNAL(aboutToShow()),this,SLOT(updatemenuColor())); | ||
| 102 | connect(menu,SIGNAL(aboutToShow()), this, SLOT(updatemenuColor())); | ||
| 132 | 103 | ||
| 133 | 104 | // set the color tooltip | |
| 134 | colorTip = new QLabel; /// (0,0,WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM); | ||
| 135 | colorTip->setMargin(1); | ||
| 136 | colorTip->setIndent(0); | ||
| 137 | /// colorTip->setAutoMask(false); | ||
| 138 | colorTip->setLineWidth(1); | ||
| 139 | #if QT_VERSION >= 300 | ||
| 140 | colorTip->setAlignment(Qt::AlignLeft | Qt::AlignTop); | ||
| 141 | #else | ||
| 142 | colorTip->setAlignment(Qt::AlignLeft | Qt::AlignTop); | ||
| 143 | #endif | ||
| 144 | /// colorTip->setAutoResize(true); | ||
| 145 | colorTip->setFrameStyle(Q3Frame::Box | Q3Frame::Plain); | ||
| 146 | colorTip->setTextFormat(Qt::RichText); | ||
| 147 | |||
| 105 | m_colorTip = new QLabel(0, Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::Tool | Qt::X11BypassWindowManagerHint); | ||
| 106 | m_colorTip->setMargin(1); | ||
| 107 | m_colorTip->setIndent(0); | ||
| 108 | m_colorTip->setAlignment(Qt::AlignLeft | Qt::AlignTop); | ||
| 109 | m_colorTip->setFrameStyle(QFrame::Plain | QFrame::Box); | ||
| 110 | m_colorTip->setTextFormat(Qt::RichText); | ||
| 148 | 111 | ||
| 149 | 112 | setMouseTracking(true); | |
| 150 | 113 | startTimer(UPDATE); | |
| 151 | 114 | } | |
| 152 | 115 | ||
| 153 | 116 | ||
| 154 | Quax::~Quax() { | ||
| 155 | delete colorTip; | ||
| 117 | Quax::~Quax() | ||
| 118 | { | ||
| 119 | delete m_colorTip; | ||
| 156 | 120 | } | |
| 157 | 121 | ||
| 158 | |||
| 159 | void Quax::enterEvent(QEvent *e) { | ||
| 160 | e=e; | ||
| 161 | |||
| 162 | m_cursorOverQuax=true; | ||
| 163 | if (m_colorTipShowed && colorTip->isHidden()) { | ||
| 164 | displayColorTip(); | ||
| 165 | } | ||
| 122 | void Quax::enterEvent(QEvent *) | ||
| 123 | { | ||
| 124 | if (m_colorTipEnabled && m_colorTip->isHidden()) | ||
| 125 | genColorTip(); | ||
| 166 | 126 | } | |
| 167 | 127 | ||
| 168 | |||
| 169 | void Quax::leaveEvent(QEvent *e) { | ||
| 170 | e=e; | ||
| 171 | |||
| 172 | m_cursorOverQuax=false; | ||
| 173 | if (m_colorTipShowed) { | ||
| 174 | colorTip->hide(); | ||
| 175 | } | ||
| 128 | void Quax::leaveEvent(QEvent *) | ||
| 129 | { | ||
| 130 | if (m_colorTipEnabled) | ||
| 131 | m_colorTip->hide(); | ||
| 176 | 132 | } | |
| 177 | 133 | ||
| 178 | |||
| 179 | void Quax::paintEvent(QPaintEvent *e) { | ||
| 180 | e=e; | ||
| 181 | |||
| 182 | if (pix_zoom.isNull()) | ||
| 134 | void Quax::paintEvent(QPaintEvent *) | ||
| 135 | { | ||
| 136 | if (m_zoomPixmap.isNull()) | ||
| 183 | 137 | return; | |
| 184 | 138 | ||
| 185 | QPainter paint(this); | ||
| 186 | paint.setClipping(true); | ||
| 187 | paint.setClipRegion(QRegion(SHAPE_INNER_X,SHAPE_INNER_Y,SHAPE_INNER_WIDTH,SHAPE_INNER_HEIGHT,QRegion::Ellipse)); | ||
| 139 | QPainter p(this); | ||
| 140 | p.setClipping(true); | ||
| 141 | p.setClipRegion(QRegion(SHAPE_INNER_X,SHAPE_INNER_Y,SHAPE_INNER_WIDTH,SHAPE_INNER_HEIGHT,QRegion::Ellipse)); | ||
| 188 | 142 | ||
| 189 | |||
| 190 | 143 | int x,y; | |
| 191 | if (pix_zoom.width()>SHAPE_INNER_WIDTH) { | ||
| 192 | x=(pix_zoom.width()-SHAPE_INNER_WIDTH)/2; | ||
| 193 | } else { | ||
| 194 | x=(SHAPE_INNER_WIDTH-pix_zoom.width())/2; | ||
| 195 | } | ||
| 196 | if (pix_zoom.height()>SHAPE_INNER_HEIGHT) { | ||
| 197 | y=(pix_zoom.height()-SHAPE_INNER_HEIGHT)/2; | ||
| 198 | } else { | ||
| 199 | y=(SHAPE_INNER_HEIGHT-pix_zoom.height())/2; | ||
| 200 | } | ||
| 144 | if (m_zoomPixmap.width() > SHAPE_INNER_WIDTH) | ||
| 145 | x=(m_zoomPixmap.width() - SHAPE_INNER_WIDTH)/2; | ||
| 146 | else | ||
| 147 | x=(SHAPE_INNER_WIDTH - m_zoomPixmap.width())/2; | ||
| 148 | if (m_zoomPixmap.height() > SHAPE_INNER_HEIGHT) | ||
| 149 | y=(m_zoomPixmap.height() - SHAPE_INNER_HEIGHT)/2; | ||
| 150 | else | ||
| 151 | y=(SHAPE_INNER_HEIGHT - m_zoomPixmap.height())/2; | ||
| 201 | 152 | x += SHAPE_INNER_X; | |
| 202 | 153 | y += SHAPE_INNER_Y; | |
| 203 | |||
| 204 | paint.drawPixmap(x,y,pix_zoom,0,0,SHAPE_INNER_WIDTH,SHAPE_INNER_HEIGHT); | ||
| 154 | p.drawPixmap(x, y, m_zoomPixmap, 0, 0, SHAPE_INNER_WIDTH, SHAPE_INNER_HEIGHT); | ||
| 205 | 155 | } | |
| 206 | 156 | ||
| 207 | void Quax::timerEvent(QTimerEvent *e) { | ||
| 208 | e=e; | ||
| 157 | void Quax::timerEvent(QTimerEvent *) | ||
| 158 | { | ||
| 209 | 159 | grab(); | |
| 210 | 160 | } | |
| 211 | 161 | ||
| 212 | void Quax::wheelEvent(QWheelEvent *e) { | ||
| 213 | if (m_ctrlKeyOn) { | ||
| 214 | if (e->delta()>0) { | ||
| 162 | void Quax::wheelEvent(QWheelEvent *e) | ||
| 163 | { | ||
| 164 | if (e->modifiers() & Qt::ControlModifier) { | ||
| 165 | if (e->delta() > 0) | ||
| 215 | 166 | rotateLeft(); | |
| 216 | } else { | ||
| 167 | else | ||
| 217 | 168 | rotateRight(); | |
| 218 | } | ||
| 219 | 169 | } else { | |
| 220 | if (e->delta()>0) { | ||
| 170 | if (e->delta() > 0) | ||
| 221 | 171 | zoomIn(); | |
| 222 | } else { | ||
| 172 | else | ||
| 223 | 173 | zoomOut(); | |
| 224 | } | ||
| 225 | 174 | } | |
| 226 | 175 | e->accept(); | |
| 227 | if (m_colorTipShowed && ! colorTip->isHidden()) { | ||
| 228 | displayColorTip(); | ||
| 229 | } | ||
| 176 | if (m_colorTipEnabled && !m_colorTip->isHidden()) | ||
| 177 | genColorTip(); | ||
| 230 | 178 | } | |
| 231 | 179 | ||
| 232 | void Quax::grab() { | ||
| 233 | QPixmap pix_grab; | ||
| 180 | void Quax::grab() | ||
| 181 | { | ||
| 234 | 182 | int x, y, w, h; | |
| 235 | 183 | int grabX, grabY, grabW, grabH, ofsX, ofsY; | |
| 236 | 184 | ||
| 237 | w = SHAPE_INNER_WIDTH/m_zoom; | ||
| 238 | h = SHAPE_INNER_HEIGHT/m_zoom; | ||
| 185 | w = SHAPE_INNER_WIDTH / m_zoom; | ||
| 186 | h = SHAPE_INNER_HEIGHT / m_zoom; | ||
| 239 | 187 | switch (m_lookAt) { | |
| 240 | case 0: // South-West | ||
| 241 | x=this->x()-w; | ||
| 242 | y=this->y()+height(); | ||
| 243 | break; | ||
| 244 | case 1: // North-West | ||
| 245 | x=this->x()-w; | ||
| 246 | y=this->y()-h; | ||
| 247 | break; | ||
| 248 | case 2: // North-East | ||
| 249 | x=this->x()+width(); | ||
| 250 | y=this->y()-h; | ||
| 251 | break; | ||
| 252 | case 3: // South-East | ||
| 253 | x=this->x()+width(); | ||
| 254 | y=this->y()+height(); | ||
| 255 | break; | ||
| 256 | default: | ||
| 257 | x=this->x(); | ||
| 258 | y=this->y(); | ||
| 259 | qWarning("m_lookAt=%d: This must not happen",m_lookAt); | ||
| 188 | case 0: // South-West | ||
| 189 | default: | ||
| 190 | x = this->x()-w; | ||
| 191 | y = this->y()+height(); | ||
| 192 | break; | ||
| 193 | case 1: // North-West | ||
| 194 | x = this->x()-w; | ||
| 195 | y = this->y()-h; | ||
| 196 | break; | ||
| 197 | case 2: // North-East | ||
| 198 | x = this->x()+width(); | ||
| 199 | y = this->y()-h; | ||
| 200 | break; | ||
| 201 | case 3: // South-East | ||
| 202 | x = this->x()+width(); | ||
| 203 | y = this->y()+height(); | ||
| 204 | break; | ||
| 260 | 205 | } | |
| 261 | 206 | ||
| 262 | 207 | // calculate grab surface to avoid garbage | |
| 263 | if (x<0) { | ||
| 208 | if (x < 0) { | ||
| 264 | 209 | grabX = 0; | |
| 265 | 210 | grabW = x+w; | |
| 266 | 211 | ofsX = -x; | |
| … | … | ||
| 218 | 218 | grabW = w; | |
| 219 | 219 | ofsX = 0; | |
| 220 | 220 | } | |
| 221 | if (y<0) { | ||
| 221 | if (y < 0) { | ||
| 222 | 222 | grabY = 0; | |
| 223 | 223 | grabH = y+h; | |
| 224 | 224 | ofsY = -y; | |
| … | … | ||
| 232 | 232 | ofsY = 0; | |
| 233 | 233 | } | |
| 234 | 234 | ||
| 235 | |||
| 236 | pix_grab.resize(w,h); | ||
| 237 | QPainter p(&pix_grab); | ||
| 238 | p.fillRect(0,0,w,h,QBrush(Qt::black)); | ||
| 239 | if (grabW>0 && grabH>0) { | ||
| 240 | QPixmap pix_temp = QPixmap::grabWindow(QApplication::desktop()->winId(),grabX,grabY,grabW,grabH); | ||
| 235 | QPixmap grabPix(w, h); | ||
| 236 | grabPix.fill(Qt::blue); | ||
| 237 | if (grabW > 0 && grabH > 0) { | ||
| 238 | QPixmap pix_temp = QPixmap::grabWindow(QApplication::desktop()->winId(), grabX, grabY, grabW, grabH); | ||
| 239 | QPainter p(&grabPix); | ||
| 241 | 240 | p.drawPixmap(ofsX,ofsY,pix_temp); | |
| 242 | 241 | } | |
| 243 | p.end(); | ||
| 244 | 242 | ||
| 245 | QMatrix m; | ||
| 246 | m.scale((double)m_zoom,(double)m_zoom); | ||
| 247 | pix_zoom=pix_grab.xForm(m); | ||
| 248 | repaint(false); | ||
| 243 | m_zoomPixmap = grabPix.transformed(QTransform::fromScale((double)m_zoom,(double)m_zoom)); | ||
| 244 | update(); | ||
| 249 | 245 | } | |
| 250 | 246 | ||
| 251 | void Quax::grabForPixel() { | ||
| 247 | void Quax::grabForPixel() | ||
| 248 | { | ||
| 252 | 249 | // get the color under cursor | |
| 253 | QPixmap pix_grab = QPixmap::grabWindow(QApplication::desktop()->winId(),QCursor::pos().x()-1,QCursor::pos().y()-1,1,1); | ||
| 254 | QImage img_grab = pix_grab.convertToImage(); | ||
| 255 | QRgb rgb_color = img_grab.pixel(0,0); | ||
| 250 | QPixmap grabPix = QPixmap::grabWindow(QApplication::desktop()->winId(), QCursor::pos().x() - 1, QCursor::pos().y() - 1, 1, 1); | ||
| 251 | QImage img_grab = grabPix.convertToImage(); | ||
| 252 | QRgb rgb_color = img_grab.pixel(0, 0); | ||
| 256 | 253 | m_colorStringDecimal = QString::number(qRed(rgb_color)) + ", " + | |
| 257 | QString::number(qGreen(rgb_color)) + ", " + | ||
| 258 | QString::number(qBlue(rgb_color)); | ||
| 254 | QString::number(qGreen(rgb_color)) + ", " + | ||
| 255 | QString::number(qBlue(rgb_color)); | ||
| 259 | 256 | m_colorStringHexaLower.sprintf("#%02x%02x%02x",qRed(rgb_color),qGreen(rgb_color),qBlue(rgb_color)); | |
| 260 | 257 | m_colorStringHexaUpper = m_colorStringHexaLower.upper(); | |
| 261 | 258 | ||
| 262 | 259 | // make a little pixmap with grabbed color | |
| 263 | QMatrix m; | ||
| 264 | m.scale((double)14,(double)14); | ||
| 265 | pix_cursor=pix_grab.xForm(m); | ||
| 260 | m_colorPixmap = grabPix.scaled(14, 14); | ||
| 266 | 261 | } | |
| 262 | #include <Q3MimeSourceFactory> | ||
| 263 | #include <QResource> | ||
| 264 | void Quax::genColorTip() | ||
| 265 | { | ||
| 266 | grabForPixel(); | ||
| 267 | Q3MimeSourceFactory::defaultFactory()->setPixmap("pixel",m_colorPixmap); | ||
| 268 | m_colorTip->setText("<qml> <img height=\"14\" width=\"14\" src=\"pixel\"> <tt>" + m_colorStringHexaUpper + "</tt></qml>"); | ||
| 267 | 269 | ||
| 268 | void Quax::displayColorTip() { | ||
| 269 | return; | ||
| 270 | /* | ||
| 271 | grabForPixel(); | ||
| 272 | Q3MimeSourceFactory::defaultFactory()->setPixmap("pixel",pix_cursor); | ||
| 273 | colorTip->setText("<qml> <img height=\"14\" width=\"14\" src=\"pixel\"> <tt>" + m_colorStringHexaUpper + "</tt></qml>"); | ||
| 274 | |||
| 275 | int x_pos, y_pos; | ||
| 276 | int x_ofs=7, y_ofs=5; | ||
| 277 | int x_margin=2, y_margin=2; | ||
| 278 | //check if tooltip get outside screen area | ||
| 279 | QRect r=colorTip->rect(); | ||
| 280 | QPoint c=QCursor::pos(); | ||
| 281 | if (c.x()+r.width()+x_ofs+x_margin > qApp->desktop()->width()) { | ||
| 282 | x_pos=c.x()-r.width()-x_ofs; | ||
| 283 | } else { | ||
| 284 | x_pos=c.x()+x_ofs; | ||
| 285 | } | ||
| 286 | if (c.y()-r.height()-y_ofs-y_margin < 0) { | ||
| 287 | y_pos=c.y()+y_ofs; | ||
| 288 | } else { | ||
| 289 | y_pos=c.y()-r.height()-y_ofs; | ||
| 290 | } | ||
| 291 | colorTip->move(x_pos,y_pos); | ||
| 292 | if (colorTip->isHidden()) colorTip->show(); | ||
| 293 | */ | ||
| 270 | int x_pos, y_pos; | ||
| 271 | int x_ofs=7, y_ofs=5; | ||
| 272 | int x_margin=2, y_margin=2; | ||
| 273 | //check if tooltip get outside screen area | ||
| 274 | QRect r = m_colorTip->rect(); | ||
| 275 | QPoint c = QCursor::pos(); | ||
| 276 | if (c.x()+r.width()+x_ofs+x_margin > qApp->desktop()->width()) | ||
| 277 | x_pos = c.x()-r.width()-x_ofs; | ||
| 278 | else | ||
| 279 | x_pos=c.x()+x_ofs; | ||
| 280 | if (c.y()-r.height()-y_ofs-y_margin < 0) | ||
| 281 | y_pos=c.y()+y_ofs; | ||
| 282 | else | ||
| 283 | y_pos=c.y()-r.height()-y_ofs; | ||
| 284 | m_colorTip->move(x_pos,y_pos); | ||
| 285 | m_colorTip->show(); | ||
| 294 | 286 | } | |
| 295 | 287 | ||
| 296 | |||
| 297 | void Quax::mousePressEvent(QMouseEvent *e) { | ||
| 288 | void Quax::mousePressEvent(QMouseEvent *e) | ||
| 289 | { | ||
| 298 | 290 | switch (e->button()) { | |
| 299 | case Qt::LeftButton: | ||
| 300 | if (m_colorTipShowed) { | ||
| 301 | copyColor(0); | ||
| 302 | setCursor(Qt::SizeAllCursor); | ||
| 303 | } else { | ||
| 304 | grabMouse(Qt::PointingHandCursor); | ||
| 305 | m_inDrag=true; | ||
| 306 | dragOffset = QCursor::pos() - QPoint(geometry().left(),geometry().top()); | ||
| 307 | } | ||
| 308 | break; | ||
| 309 | case Qt::RightButton: | ||
| 310 | menu->popup(QCursor::pos()); | ||
| 311 | break; | ||
| 312 | default: | ||
| 313 | break; | ||
| 291 | case Qt::LeftButton: | ||
| 292 | if (m_colorTipEnabled) { | ||
| 293 | colorToClipboard(0); | ||
| 294 | setCursor(Qt::SizeAllCursor); | ||
| 295 | } else { | ||
| 296 | grabMouse(Qt::PointingHandCursor); | ||
| 297 | m_inDrag = true; | ||
| 298 | dragOffset = QCursor::pos() - QPoint(geometry().left(),geometry().top()); | ||
| 299 | } | ||
| 300 | break; | ||
| 301 | case Qt::RightButton: | ||
| 302 | menu->popup(QCursor::pos()); | ||
| 303 | break; | ||
| 304 | default: | ||
| 305 | break; | ||
| 314 | 306 | } | |
| 315 | 307 | } | |
| 316 | 308 | ||
| 317 | void Quax::mouseReleaseEvent(QMouseEvent *e) { | ||
| 318 | switch (e->button()) { | ||
| 319 | case Qt::LeftButton: | ||
| 320 | if (m_colorTipShowed) { | ||
| 321 | setCursor(Qt::CrossCursor); | ||
| 322 | } else { | ||
| 323 | releaseMouse(); | ||
| 324 | m_inDrag=false; | ||
| 325 | } | ||
| 326 | break; | ||
| 327 | default: | ||
| 328 | break; | ||
| 329 | } | ||
| 309 | void Quax::mouseMoveEvent(QMouseEvent *) | ||
| 310 | { | ||
| 311 | if (m_colorTipEnabled) | ||
| 312 | genColorTip(); | ||
| 313 | if (m_inDrag && this == mouseGrabber()) | ||
| 314 | move(QCursor::pos() - dragOffset); | ||
| 330 | 315 | } | |
| 331 | 316 | ||
| 332 | void Quax::mouseMoveEvent(QMouseEvent *e) { | ||
| 333 | e=e; | ||
| 334 | |||
| 335 | if (m_colorTipShowed && m_cursorOverQuax) { | ||
| 336 | displayColorTip(); | ||
| 317 | void Quax::mouseReleaseEvent(QMouseEvent *e) | ||
| 318 | { | ||
| 319 | switch (e->button()) { | ||
| 320 | case Qt::LeftButton: | ||
| 321 | if (m_colorTipEnabled) | ||
| 322 | setCursor(Qt::CrossCursor); | ||
| 323 | else { | ||
| 324 | releaseMouse(); | ||
| 325 | m_inDrag = false; | ||
| 326 | } | ||
| 327 | break; | ||
| 328 | default: | ||
| 329 | break; | ||
| 337 | 330 | } | |
| 338 | if (!m_inDrag || this != mouseGrabber()) return; | ||
| 339 | move(QCursor::pos()-dragOffset); | ||
| 340 | 331 | } | |
| 341 | 332 | ||
| 342 | |||
| 343 | void Quax::keyReleaseEvent(QKeyEvent *e) { | ||
| 344 | if (m_ctrlKeyOn) { | ||
| 345 | if (!(e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control)) { | ||
| 346 | m_ctrlKeyOn=false; | ||
| 347 | } | ||
| 348 | } | ||
| 349 | |||
| 350 | if (m_colorTipShowed) { | ||
| 351 | if (e->key() == Qt::Key_Control ||e->key() == Qt::Key_Shift) { | ||
| 352 | m_colorTipShowed=false; | ||
| 333 | void Quax::keyReleaseEvent(QKeyEvent *e) | ||
| 334 | { | ||
| 335 | if (m_colorTipEnabled) { | ||
| 336 | if (e->key() == Qt::Key_Control || e->key() == Qt::Key_Shift) { | ||
| 337 | m_colorTipEnabled = false; | ||
| 338 | m_colorTip->hide(); | ||
| 353 | 339 | setCursor(Qt::PointingHandCursor); | |
| 354 | colorTip->hide(); | ||
| 355 | 340 | } | |
| 356 | 341 | } | |
| 357 | 342 | } | |
| 358 | |||
| 359 | void Quax::keyPressEvent(QKeyEvent *e) { | ||
| 360 | QPoint dist(0,0); | ||
| 361 | |||
| 362 | if (!(e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control)) { | ||
| 363 | m_ctrlKeyOn=true; | ||
| 343 | void Quax::keyPressEvent(QKeyEvent *e) | ||
| 344 | { | ||
| 345 | if (!m_colorTipEnabled && e->modifiers() & Qt::ShiftModifier && e->modifiers() & Qt::ControlModifier) { | ||
| 364 | 346 | e->ignore(); | |
| 347 | m_colorTipEnabled = true; | ||
| 348 | setCursor(Qt::CrossCursor); | ||
| 349 | genColorTip(); | ||
| 365 | 350 | return; | |
| 366 | 351 | } | |
| 367 | 352 | ||
| 368 | if (!m_colorTipShowed) { | ||
| 369 | if (((e->state() & Qt::ShiftButton) && (e->key() == Qt::Key_Control)) || | ||
| 370 | ((e->state() & Qt::ControlButton) && (e->key() == Qt::Key_Shift))) { | ||
| 371 | m_colorTipShowed=true; | ||
| 372 | m_ctrlKeyOn=false; | ||
| 373 | setCursor(Qt::CrossCursor); | ||
| 374 | displayColorTip(); | ||
| 353 | QPoint dist(0, 0); | ||
| 354 | switch (e->key()) { | ||
| 355 | case Qt::Key_Left: | ||
| 356 | dist.setX(-1); | ||
| 357 | break; | ||
| 358 | case Qt::Key_Right: | ||
| 359 | dist.setX(1); | ||
| 360 | break; | ||
| 361 | case Qt::Key_Up: | ||
| 362 | dist.setY(-1); | ||
| 363 | break; | ||
| 364 | case Qt::Key_Down: | ||
| 365 | dist.setY(1); | ||
| 366 | break; | ||
| 367 | case Qt::Key_Equal: | ||
| 368 | case Qt::Key_Plus: | ||
| 369 | zoomIn(); | ||
| 370 | break; | ||
| 371 | case Qt::Key_Underscore: | ||
| 372 | case Qt::Key_Minus: | ||
| 373 | zoomOut(); | ||
| 374 | break; | ||
| 375 | default: | ||
| 375 | 376 | e->ignore(); | |
| 376 | 377 | return; | |
| 377 | } | ||
| 378 | 378 | } | |
| 379 | |||
| 380 | |||
| 381 | |||
| 382 | switch (e->key()) { | ||
| 383 | case Qt::Key_Left: | ||
| 384 | dist.setX(-1); | ||
| 385 | break; | ||
| 386 | case Qt::Key_Right: | ||
| 387 | dist.setX(1); | ||
| 388 | break; | ||
| 389 | case Qt::Key_Up: | ||
| 390 | dist.setY(-1); | ||
| 391 | break; | ||
| 392 | case Qt::Key_Down: | ||
| 393 | dist.setY(1); | ||
| 394 | break; | ||
| 395 | case Qt::Key_Equal: | ||
| 396 | zoomIn(); | ||
| 397 | break; | ||
| 398 | case Qt::Key_Underscore: | ||
| 399 | zoomOut(); | ||
| 400 | break; | ||
| 401 | default: | ||
| 402 | e->ignore(); | ||
| 403 | return; | ||
| 404 | } | ||
| 405 | if (e->state() & Qt::ShiftButton) { | ||
| 379 | if (e->modifiers() & Qt::ShiftModifier) | ||
| 406 | 380 | dist *= 10; | |
| 407 | } | ||
| 408 | move(pos()+dist); | ||
| 381 | move(pos() + dist); | ||
| 409 | 382 | } | |
| 410 | 383 | ||
| 411 | void Quax::help() { | ||
| 412 | #if QT_VERSION >= 300 | ||
| 413 | #ifdef _OS_WIN32_ | ||
| 414 | #else | ||
| 415 | QString helpApp = "kfmclient"; | ||
| 416 | |||
| 417 | Q3Process *proc = new Q3Process(this); | ||
| 418 | proc->addArgument(helpApp); | ||
| 419 | proc->addArgument("openURL"); | ||
| 420 | proc->addArgument("help:quax"); | ||
| 421 | proc->closeStdin(); | ||
| 422 | if (!proc->start()) { | ||
| 423 | QMessageBox::critical(this,QObject::tr("Help Error"), | ||
| 424 | QObject::tr("<qml>There was an error executing <b>%1</b> application. " | ||
| 425 | "Please check your KDE installation. You may try to open an <b>xterm</b> " | ||
| 426 | "window and run <tt>man quax</tt> from there.</qml>").arg(helpApp), | ||
| 427 | QMessageBox::Ok, Qt::NoButton, Qt::NoButton); | ||
| 428 | } | ||
| 429 | #endif | ||
| 430 | #endif | ||
| 384 | void Quax::help() | ||
| 385 | { | ||
| 386 | if (QDesktopServices::openUrl(QUrl("help:quax"))) | ||
| 387 | return; | ||
| 388 | QMessageBox::warning(this, tr("Help Error"), | ||
| 389 | tr("<qml>There was an loading the help application." | ||
| 390 | "Please check your KDE installation. You may try to open an <b>xterm</b> " | ||
| 391 | "window and run <tt>man quax</tt> from there.</qml>"), | ||
| 392 | QMessageBox::Ok); | ||
| 431 | 393 | } | |
| 432 | 394 | ||
| 433 | void Quax::about() { | ||
| 434 | QMessageBox::about(this,QObject::tr("About Quax %1").arg(QUAX_VERSION "-" QUAX_RELEASE),QObject::tr( | ||
| 395 | void Quax::about() | ||
| 396 | { | ||
| 397 | QMessageBox::about(this, QObject::tr("About Quax %1").arg(QUAX_VERSION "-" QUAX_RELEASE), QObject::tr( | ||
| 435 | 398 | "<p><b>Quax</b> is a little magnifing tool for X. Quax homepage is " | |
| 436 | 399 | "at <tt><http://www.ro.kde.org/quax/></tt>." | |
| 437 | 400 | "</p><p>This is Quax version %1." | |
| … | … | ||
| 402 | 402 | "<dl>" | |
| 403 | 403 | "<dt><nobr>Claudiu Costin <tt><claudiuc@kde.org></tt></nobr></dt>" | |
| 404 | 404 | "<dd>coding, documentation, packaging</dd>" | |
| 405 | "<dt><nobr>Enrico Ros <tt><enrico.ros@gmail.com></tt></nobr></dt>" | ||
| 406 | "<dd>porting to Qt4 and cleanups</dd>" | ||
| 405 | 407 | "<dt><nobr>Vlad Oancea <tt><xtrim@fx.ro></tt></nobr></dt>" | |
| 406 | 408 | "<dd>Quax skin design</dd>" | |
| 407 | 409 | "</dl></p>").arg(QUAX_VERSION "-" QUAX_RELEASE)); | |
| 408 | 410 | } | |
| 409 | 411 | ||
| 410 | void Quax::aboutQt() { | ||
| 411 | QMessageBox::aboutQt(this,QObject::tr("About Qt")); | ||
| 412 | void Quax::aboutQt() | ||
| 413 | { | ||
| 414 | QMessageBox::aboutQt(this, tr("About Qt")); | ||
| 412 | 415 | } | |
| 413 | 416 | ||
| 414 | void Quax::zoomIn() { | ||
| 415 | if (m_zoom < ZOOM_SCALE_MAX) { | ||
| 416 | menuZoom->setItemChecked(zoomid[m_zoom],false); | ||
| 417 | m_zoom++; | ||
| 418 | menuZoom->setItemChecked(zoomid[m_zoom],true); | ||
| 419 | } | ||
| 417 | void Quax::zoomIn() | ||
| 418 | { | ||
| 419 | if (m_zoom >= ZOOM_SCALE_MAX) | ||
| 420 | return; | ||
| 421 | menuZoom->setItemChecked(zoomid[m_zoom], false); | ||
| 422 | m_zoom++; | ||
| 423 | menuZoom->setItemChecked(zoomid[m_zoom], true); | ||
| 420 | 424 | } | |
| 421 | 425 | ||
| 422 | void Quax::zoomOut() { | ||
| 423 | if (m_zoom > ZOOM_SCALE_MIN) { | ||
| 424 | menuZoom->setItemChecked(zoomid[m_zoom],false); | ||
| 425 | m_zoom--; | ||
| 426 | menuZoom->setItemChecked(zoomid[m_zoom],true); | ||
| 427 | } | ||
| 426 | void Quax::zoomOut() | ||
| 427 | { | ||
| 428 | if (m_zoom <= ZOOM_SCALE_MIN) | ||
| 429 | return; | ||
| 430 | menuZoom->setItemChecked(zoomid[m_zoom], false); | ||
| 431 | m_zoom--; | ||
| 432 | menuZoom->setItemChecked(zoomid[m_zoom], true); | ||
| 428 | 433 | } | |
| 429 | 434 | ||
| 430 | void Quax::zoomTo(int pos) { | ||
| 435 | void Quax::zoomTo(int pos) | ||
| 436 | { | ||
| 431 | 437 | for (int i = ZOOM_SCALE_MIN; i <= ZOOM_SCALE_MAX; i++) | |
| 432 | 438 | if (zoomid[i]==pos) { | |
| 433 | menuZoom->setItemChecked(zoomid[i],true); | ||
| 439 | menuZoom->setItemChecked(zoomid[i], true); | ||
| 434 | 440 | m_zoom=i; | |
| 435 | 441 | } else { | |
| 436 | menuZoom->setItemChecked(zoomid[i],false); | ||
| 442 | menuZoom->setItemChecked(zoomid[i], false); | ||
| 437 | 443 | } | |
| 438 | 444 | } | |
| 439 | 445 | ||
| 440 | void Quax::rotateNorthWest() { | ||
| 441 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 442 | m_lookAt=1; | ||
| 443 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 446 | void Quax::rotateNorthWest() | ||
| 447 | { | ||
| 448 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 449 | m_lookAt = 1; | ||
| 450 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 444 | 451 | rotate(m_lookAt); | |
| 445 | 452 | } | |
| 446 | 453 | ||
| 447 | void Quax::rotateSouthWest() { | ||
| 448 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 449 | m_lookAt=0; | ||
| 450 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 454 | void Quax::rotateSouthWest() | ||
| 455 | { | ||
| 456 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 457 | m_lookAt = 0; | ||
| 458 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 451 | 459 | rotate(m_lookAt); | |
| 452 | 460 | } | |
| 453 | 461 | ||
| 454 | void Quax::rotateNorthEast() { | ||
| 455 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 456 | m_lookAt=2; | ||
| 457 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 462 | void Quax::rotateNorthEast() | ||
| 463 | { | ||
| 464 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 465 | m_lookAt = 2; | ||
| 466 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 458 | 467 | rotate(m_lookAt); | |
| 459 | 468 | } | |
| 460 | 469 | ||
| 461 | void Quax::rotateSouthEast() { | ||
| 462 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 463 | m_lookAt=3; | ||
| 464 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 470 | void Quax::rotateSouthEast() | ||
| 471 | { | ||
| 472 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 473 | m_lookAt = 3; | ||
| 474 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 465 | 475 | rotate(m_lookAt); | |
| 466 | 476 | } | |
| 467 | 477 | ||
| 468 | void Quax::rotateLeft() { | ||
| 469 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 470 | if (m_lookAt==0) { | ||
| 471 | m_lookAt=3; | ||
| 472 | } else { | ||
| 478 | void Quax::rotateLeft() | ||
| 479 | { | ||
| 480 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 481 | if (m_lookAt == 0) | ||
| 482 | m_lookAt = 3; | ||
| 483 | else | ||
| 473 | 484 | m_lookAt--; | |
| 474 | } | ||
| 475 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 485 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 476 | 486 | rotate(m_lookAt); | |
| 477 | 487 | } | |
| 478 | 488 | ||
| 479 | void Quax::rotateRight() { | ||
| 480 | menuLook->setItemChecked(lookid[m_lookAt],false); | ||
| 481 | if (m_lookAt==3) { | ||
| 482 | m_lookAt=0; | ||
| 483 | } else { | ||
| 489 | void Quax::rotateRight() | ||
| 490 | { | ||
| 491 | menuLook->setItemChecked(lookid[m_lookAt], false); | ||
| 492 | if (m_lookAt == 3) | ||
| 493 | m_lookAt = 0; | ||
| 494 | else | ||
| 484 | 495 | m_lookAt++; | |
| 485 | } | ||
| 486 | menuLook->setItemChecked(lookid[m_lookAt],true); | ||
| 496 | menuLook->setItemChecked(lookid[m_lookAt], true); | ||
| 487 | 497 | rotate(m_lookAt); | |
| 488 | 498 | } | |
| 489 | 499 | ||
| 490 | void Quax::rotate(int pos) { | ||
| 491 | QMatrix m; | ||
| 492 | m.rotate(pos*90.0); | ||
| 493 | setBackgroundPixmap(pix.xForm(m)); | ||
| 494 | /// setMask(*(pix_alpha.xForm(m)).mask()); | ||
| 500 | void Quax::rotate(int pos) | ||
| 501 | { | ||
| 502 | QTransform rot; | ||
| 503 | rot.rotate(pos * 90.0); | ||
| 504 | QPalette pal; | ||
| 505 | pal.setBrush(QPalette::Window, QPixmap(mag_xpm).transformed(rot)); | ||
| 506 | setPalette(pal); | ||
| 507 | setMask(QPixmap(mag_alpha_xpm).transformed(rot).mask()); | ||
| 495 | 508 | } | |
| 496 | 509 | ||
| 497 | |||
| 498 | void Quax::copyColor(int id) { | ||
| 499 | |||
| 500 | if (id == colorid[1] ) { | ||
| 510 | void Quax::colorToClipboard(int id) | ||
| 511 | { | ||
| 512 | if (id == colorid[1]) { | ||
| 501 | 513 | qApp->clipboard()->setText(m_colorStringDecimal); | |
| 502 | 514 | } else if (id == colorid[2]) { | |
| 503 | 515 | // this get called when user press Ctrl+C | |
| … | … | ||
| 523 | 523 | } else if (id == colorid[3] || id == 0) { | |
| 524 | 524 | // id=0 if user click when color tip is displayed | |
| 525 | 525 | qApp->clipboard()->setText(m_colorStringHexaUpper); | |
| 526 | } else { | ||
| 526 | } else | ||
| 527 | 527 | qWarning("id=%d: This must not happen",id); | |
| 528 | } | ||
| 529 | 528 | } | |
| 530 | 529 | ||
| 531 | void Quax::updateMenuColor() { | ||
| 530 | void Quax::updateMenuColor() | ||
| 531 | { | ||
| 532 | 532 | grabForPixel(); | |
| 533 | #if QT_VERSION > 300 | ||
| 534 | ///m_pixelColorIcon->clearGenerated(); | ||
| 535 | #endif | ||
| 536 | m_pixelColorIcon->reset(pix_cursor,QIcon::Small); | ||
| 537 | |||
| 538 | menu->changeItem(colorid[0],QIcon(pix_cursor),QObject::tr("Copy Color")); | ||
| 539 | menuColor->changeItem(colorid[1],m_colorStringDecimal); | ||
| 540 | menuColor->changeItem(colorid[2],m_colorStringHexaLower); | ||
| 541 | menuColor->changeItem(colorid[3],m_colorStringHexaUpper); | ||
| 533 | menu->changeItem(colorid[0], QIcon(m_colorPixmap), QObject::tr("Copy Color")); | ||
| 534 | menuColor->changeItem(colorid[1], m_colorStringDecimal); | ||
| 535 | menuColor->changeItem(colorid[2], m_colorStringHexaLower); | ||
| 536 | menuColor->changeItem(colorid[3], m_colorStringHexaUpper); | ||
| 542 | 537 | } |
src/quax.h
(13 / 19)
|   | |||
| 79 | 79 | ||
| 80 | 80 | protected: | |
| 81 | 81 | /** | |
| 82 | * Show color tooltip when mouse enter Quax area, and set | ||
| 83 | * the @p m_cursorOverQuax flag. | ||
| 82 | * Show color tooltip when mouse enter Quax area. | ||
| 84 | 83 | */ | |
| 85 | 84 | void enterEvent(QEvent *e); | |
| 86 | 85 | /** | |
| 87 | * Hide color tooltip if shown, and set the @p m_cursorOverQuax flag. | ||
| 86 | * Hide color tooltip if shown. | ||
| 88 | 87 | */ | |
| 89 | 88 | void leaveEvent(QEvent *e); | |
| 90 | 89 | /** | |
| … | … | ||
| 92 | 92 | */ | |
| 93 | 93 | void mousePressEvent(QMouseEvent *e); | |
| 94 | 94 | /** | |
| 95 | * Executed when user release one mouse button. | ||
| 96 | */ | ||
| 97 | void mouseReleaseEvent(QMouseEvent *e); | ||
| 98 | /** | ||
| 99 | 95 | * Executed when user release move the mouse. If the color tip is enabled, | |
| 100 | 96 | * then displayed color is updated as well the tooltip position. | |
| 101 | 97 | * If is @p m_inDrag is true, then Quax position is updated (dragged) | |
| … | … | ||
| 99 | 99 | */ | |
| 100 | 100 | void mouseMoveEvent(QMouseEvent *e); | |
| 101 | 101 | /** | |
| 102 | * Executed when user release one mouse button. | ||
| 103 | */ | ||
| 104 | void mouseReleaseEvent(QMouseEvent *e); | ||
| 105 | /** | ||
| 102 | 106 | * Get the modifier keys status and display color tooltip if Shift and Ctrl | |
| 103 | 107 | * are both pressed down. If cursor keys are pressed, then adjust Quax | |
| 104 | 108 | * position by one pixel or by ten pixels if Shift is down. | |
| … | … | ||
| 131 | 131 | QString m_colorStringDecimal, ///< the current color under mouse as decimals comma seperated | |
| 132 | 132 | m_colorStringHexaLower, ///< the current color under mouse as web RGB with lower hexadecimals | |
| 133 | 133 | m_colorStringHexaUpper; ///< the current color under mouse as web RGB with upper hexadecimals | |
| 134 | QIcon *m_pixelColorIcon; ///< The icon set which is used in QML content from @ref colorTip | ||
| 135 | QLabel *colorTip; ///< The tool tip for displaying current color under mouse | ||
| 134 | QLabel *m_colorTip; ///< The tool tip for displaying current color under mouse | ||
| 136 | 135 | QMenu *menu, ///< The main menu of Quax | |
| 137 | 136 | *menuZoom, ///< Menu for zoom levels and zoom in and zoom out items | |
| 138 | 137 | *menuLook, ///< The "Look at" menu | |
| 139 | 138 | *menuColor; ///< Menu for coying textual representation into clipboard | |
| 140 | QPixmap pix, ///< Quax skin image | ||
| 141 | pix_alpha, ///< Quax alpha mask for skin image | ||
| 142 | pix_zoom, ///< The grabbed image zoomend and clipped | ||
| 143 | pix_cursor; ///< The icon used in color menu item and color tooltip | ||
| 139 | QPixmap m_zoomPixmap, ///< The grabbed image zoomend and clipped | ||
| 140 | m_colorPixmap; ///< The icon used in color menu item and color tooltip | ||
| 144 | 141 | bool m_inDrag, ///< if true, the user is dragging the Quax | |
| 145 | m_colorTipShowed, ///< if true, the color tooltip is displayed | ||
| 146 | m_cursorOverQuax, ///< if true, mouse cursor is over Quax surface | ||
| 147 | m_ctrlKeyOn; ///< if true, the Ctrl key is pressed down | ||
| 142 | m_colorTipEnabled;///< if true, the color tooltip is displayed | ||
| 148 | 143 | int m_zoom, ///< current zoom level | |
| 149 | 144 | m_lookAt; ///< current quadrant direction where Quax "look at" | |
| 150 | 145 | QPoint dragOffset; ///< the offset between Quax position and new mouse position | |
| … | … | ||
| 148 | 148 | colorid; ///< mapping between text color type and @ref menucolor menu item ids | |
| 149 | 149 | ||
| 150 | 150 | /** | |
| 151 | * It grab desktop area, scale it, clip it with circle region, | ||
| 151 | * It grabs the desktop area, scale it, clip it with circle region, | ||
| 152 | 152 | * and then paint on Quax area. | |
| 153 | 153 | */ | |
| 154 | 154 | void grab(); | |
| … | … | ||
| 157 | 157 | * is updated runnning @ref grabForPixel(). If tooltip will be displayed | |
| 158 | 158 | * clipped by screen margins, then it will be repositioned before moving. | |
| 159 | 159 | */ | |
| 160 | void displayColorTip(); | ||
| 160 | void genColorTip(); | ||
| 161 | 161 | /** | |
| 162 | 162 | * Grab exactly one pixel under mouse cursor to show it in color tooltip. | |
| 163 | 163 | */ | |
| … | … | ||
| 227 | 227 | * @ref grabForPixel() prior to cliboard operation. | |
| 228 | 228 | * @param id the menu identificator to get what color menu item was selected | |
| 229 | 229 | */ | |
| 230 | void copyColor(int id); | ||
| 230 | void colorToClipboard(int id); | ||
| 231 | 231 | /** | |
| 232 | 232 | * Build the menu left pixmap from the grabed color under mouse. This is slot is | |
| 233 | 233 | * called from QPopupMenu::aboutToShow signal. |

