| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | #include "qcolordialog.h" | - |
| 41 | | - |
| 42 | #ifndef QT_NO_COLORDIALOG | - |
| 43 | | - |
| 44 | #include "qapplication.h" | - |
| 45 | #include "qdesktopwidget.h" | - |
| 46 | #include "qdrawutil.h" | - |
| 47 | #include "qevent.h" | - |
| 48 | #include "qimage.h" | - |
| 49 | #include "qdrag.h" | - |
| 50 | #include "qlabel.h" | - |
| 51 | #include "qlayout.h" | - |
| 52 | #include "qlineedit.h" | - |
| 53 | #include "qmenu.h" | - |
| 54 | #include "qpainter.h" | - |
| 55 | #include "qpixmap.h" | - |
| 56 | #include "qpushbutton.h" | - |
| 57 | #include "qsettings.h" | - |
| 58 | #include "qsharedpointer.h" | - |
| 59 | #include "qstyle.h" | - |
| 60 | #include "qstyleoption.h" | - |
| 61 | #include "qvalidator.h" | - |
| 62 | #include "qmimedata.h" | - |
| 63 | #include "qspinbox.h" | - |
| 64 | #include "qdialogbuttonbox.h" | - |
| 65 | #include "qscreen.h" | - |
| 66 | #include "qcursor.h" | - |
| 67 | #include "qtimer.h" | - |
| 68 | #include "qwindow.h" | - |
| 69 | | - |
| 70 | #include "private/qdialog_p.h" | - |
| 71 | | - |
| 72 | #include <algorithm> | - |
| 73 | | - |
| 74 | QT_BEGIN_NAMESPACE | - |
| 75 | | - |
| 76 | namespace { | - |
| 77 | class QColorLuminancePicker; | - |
| 78 | class QColorPicker; | - |
| 79 | class QColorShower; | - |
| 80 | class QWellArray; | - |
| 81 | class QColorPickingEventFilter; | - |
| 82 | } | - |
| 83 | | - |
| 84 | class QColorDialogPrivate : public QDialogPrivate | - |
| 85 | { | - |
| 86 | Q_DECLARE_PUBLIC(QColorDialog) | - |
| 87 | | - |
| 88 | public: | - |
| 89 | enum SetColorMode { | - |
| 90 | ShowColor = 0x1, | - |
| 91 | SelectColor = 0x2, | - |
| 92 | SetColorAll = ShowColor | SelectColor | - |
| 93 | }; | - |
| 94 | | - |
| 95 | QColorDialogPrivate() : options(new QColorDialogOptions) | - |
| 96 | #ifdef Q_OS_WIN32 | - |
| 97 | , updateTimer(0) | - |
| 98 | #endif | - |
| 99 | {} | - |
| 100 | | - |
| 101 | QPlatformColorDialogHelper *platformColorDialogHelper() const | - |
| 102 | { return static_cast<QPlatformColorDialogHelper *>(platformHelper()); } | - |
| 103 | | - |
| 104 | void init(const QColor &initial); | - |
| 105 | void initWidgets(); | - |
| 106 | QRgb currentColor() const; | - |
| 107 | QColor currentQColor() const; | - |
| 108 | void setCurrentColor(const QColor &color, SetColorMode setColorMode = SetColorAll); | - |
| 109 | void setCurrentRgbColor(QRgb rgb); | - |
| 110 | void setCurrentQColor(const QColor &color); | - |
| 111 | bool selectColor(const QColor &color); | - |
| 112 | QColor grabScreenColor(const QPoint &p); | - |
| 113 | | - |
| 114 | int currentAlpha() const; | - |
| 115 | void setCurrentAlpha(int a); | - |
| 116 | void showAlpha(bool b); | - |
| 117 | bool isAlphaVisible() const; | - |
| 118 | void retranslateStrings(); | - |
| 119 | | - |
| 120 | void _q_addCustom(); | - |
| 121 | | - |
| 122 | void _q_newHsv(int h, int s, int v); | - |
| 123 | void _q_newColorTypedIn(QRgb rgb); | - |
| 124 | void _q_nextCustom(int, int); | - |
| 125 | void _q_newCustom(int, int); | - |
| 126 | void _q_newStandard(int, int); | - |
| 127 | void _q_pickScreenColor(); | - |
| 128 | void _q_updateColorPicking(); | - |
| 129 | void updateColorLabelText(const QPoint &); | - |
| 130 | void updateColorPicking(const QPoint &pos); | - |
| 131 | void releaseColorPicking(); | - |
| 132 | bool handleColorPickingMouseMove(QMouseEvent *e); | - |
| 133 | bool handleColorPickingMouseButtonRelease(QMouseEvent *e); | - |
| 134 | bool handleColorPickingKeyPress(QKeyEvent *e); | - |
| 135 | | - |
| 136 | bool canBeNativeDialog() const Q_DECL_OVERRIDE; | - |
| 137 | | - |
| 138 | QWellArray *custom; | - |
| 139 | QWellArray *standard; | - |
| 140 | | - |
| 141 | QDialogButtonBox *buttons; | - |
| 142 | QVBoxLayout *leftLay; | - |
| 143 | QColorPicker *cp; | - |
| 144 | QColorLuminancePicker *lp; | - |
| 145 | QColorShower *cs; | - |
| 146 | QLabel *lblBasicColors; | - |
| 147 | QLabel *lblCustomColors; | - |
| 148 | QLabel *lblScreenColorInfo; | - |
| 149 | QPushButton *ok; | - |
| 150 | QPushButton *cancel; | - |
| 151 | QPushButton *addCusBt; | - |
| 152 | QPushButton *screenColorPickerButton; | - |
| 153 | QColor selectedQColor; | - |
| 154 | int nextCust; | - |
| 155 | bool smallDisplay; | - |
| 156 | bool screenColorPicking; | - |
| 157 | QColorPickingEventFilter *colorPickingEventFilter; | - |
| 158 | QRgb beforeScreenColorPicking; | - |
| 159 | QSharedPointer<QColorDialogOptions> options; | - |
| 160 | | - |
| 161 | QPointer<QObject> receiverToDisconnectOnClose; | - |
| 162 | QByteArray memberToDisconnectOnClose; | - |
| 163 | #ifdef Q_OS_WIN32 | - |
| 164 | QTimer *updateTimer; | - |
| 165 | QWindow dummyTransparentWindow; | - |
| 166 | #endif | - |
| 167 | | - |
| 168 | private: | - |
| 169 | virtual void initHelper(QPlatformDialogHelper *h) Q_DECL_OVERRIDE; | - |
| 170 | virtual void helperPrepareShow(QPlatformDialogHelper *h) Q_DECL_OVERRIDE; | - |
| 171 | }; | - |
| 172 | | - |
| 173 | | - |
| 174 | | - |
| 175 | namespace { | - |
| 176 | | - |
| 177 | class QWellArray : public QWidget | - |
| 178 | { | - |
| 179 | Q_OBJECT | - |
| 180 | Q_PROPERTY(int selectedColumn READ selectedColumn) | - |
| 181 | Q_PROPERTY(int selectedRow READ selectedRow) | - |
| 182 | | - |
| 183 | public: | - |
| 184 | QWellArray(int rows, int cols, QWidget* parent=0); | - |
| 185 | ~QWellArray() {} | - |
| 186 | QString cellContent(int row, int col) const; | - |
| 187 | | - |
| 188 | int selectedColumn() const { return selCol; } | - |
| 189 | int selectedRow() const { return selRow; } | - |
| 190 | | - |
| 191 | virtual void setCurrent(int row, int col); | - |
| 192 | virtual void setSelected(int row, int col); | - |
| 193 | | - |
| 194 | QSize sizeHint() const Q_DECL_OVERRIDE; | - |
| 195 | | - |
| 196 | inline int cellWidth() const | - |
| 197 | { return cellw; } | - |
| 198 | | - |
| 199 | inline int cellHeight() const | - |
| 200 | { return cellh; } | - |
| 201 | | - |
| 202 | inline int rowAt(int y) const | - |
| 203 | { return y / cellh; } | - |
| 204 | | - |
| 205 | inline int columnAt(int x) const | - |
| 206 | { if (isRightToLeft()) return ncols - (x / cellw) - 1; return x / cellw; } | - |
| 207 | | - |
| 208 | inline int rowY(int row) const | - |
| 209 | { return cellh * row; } | - |
| 210 | | - |
| 211 | inline int columnX(int column) const | - |
| 212 | { if (isRightToLeft()) return cellw * (ncols - column - 1); return cellw * column; } | - |
| 213 | | - |
| 214 | inline int numRows() const | - |
| 215 | { return nrows; } | - |
| 216 | | - |
| 217 | inline int numCols() const | - |
| 218 | {return ncols; } | - |
| 219 | | - |
| 220 | inline QRect cellRect() const | - |
| 221 | { return QRect(0, 0, cellw, cellh); } | - |
| 222 | | - |
| 223 | inline QSize gridSize() const | - |
| 224 | { return QSize(ncols * cellw, nrows * cellh); } | - |
| 225 | | - |
| 226 | QRect cellGeometry(int row, int column) | - |
| 227 | { | - |
| 228 | QRect r; | - |
| 229 | if (row >= 0 && row < nrows && column >= 0 && column < ncols) | - |
| 230 | r.setRect(columnX(column), rowY(row), cellw, cellh); | - |
| 231 | return r; | - |
| 232 | } | - |
| 233 | | - |
| 234 | inline void updateCell(int row, int column) { update(cellGeometry(row, column)); } | - |
| 235 | | - |
| 236 | signals: | - |
| 237 | void selected(int row, int col); | - |
| 238 | void currentChanged(int row, int col); | - |
| 239 | | - |
| 240 | protected: | - |
| 241 | virtual void paintCell(QPainter *, int row, int col, const QRect&); | - |
| 242 | virtual void paintCellContents(QPainter *, int row, int col, const QRect&); | - |
| 243 | | - |
| 244 | void mousePressEvent(QMouseEvent*) Q_DECL_OVERRIDE; | - |
| 245 | void mouseReleaseEvent(QMouseEvent*) Q_DECL_OVERRIDE; | - |
| 246 | void keyPressEvent(QKeyEvent*) Q_DECL_OVERRIDE; | - |
| 247 | void focusInEvent(QFocusEvent*) Q_DECL_OVERRIDE; | - |
| 248 | void focusOutEvent(QFocusEvent*) Q_DECL_OVERRIDE; | - |
| 249 | void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; | - |
| 250 | | - |
| 251 | private: | - |
| 252 | Q_DISABLE_COPY(QWellArray) | - |
| 253 | | - |
| 254 | int nrows; | - |
| 255 | int ncols; | - |
| 256 | int cellw; | - |
| 257 | int cellh; | - |
| 258 | int curRow; | - |
| 259 | int curCol; | - |
| 260 | int selRow; | - |
| 261 | int selCol; | - |
| 262 | }; | - |
| 263 | | - |
| 264 | void QWellArray::paintEvent(QPaintEvent *e) | - |
| 265 | { | - |
| 266 | QRect r = e->rect(); | - |
| 267 | int cx = r.x(); | - |
| 268 | int cy = r.y(); | - |
| 269 | int ch = r.height(); | - |
| 270 | int cw = r.width(); | - |
| 271 | int colfirst = columnAt(cx); | - |
| 272 | int collast = columnAt(cx + cw); | - |
| 273 | int rowfirst = rowAt(cy); | - |
| 274 | int rowlast = rowAt(cy + ch); | - |
| 275 | | - |
| 276 | if (isRightToLeft()) { | - |
| 277 | int t = colfirst; | - |
| 278 | colfirst = collast; | - |
| 279 | collast = t; | - |
| 280 | } | - |
| 281 | | - |
| 282 | QPainter painter(this); | - |
| 283 | QPainter *p = &painter; | - |
| 284 | QRect rect(0, 0, cellWidth(), cellHeight()); | - |
| 285 | | - |
| 286 | | - |
| 287 | if (collast < 0 || collast >= ncols) | - |
| 288 | collast = ncols-1; | - |
| 289 | if (rowlast < 0 || rowlast >= nrows) | - |
| 290 | rowlast = nrows-1; | - |
| 291 | | - |
| 292 | | - |
| 293 | for (int r = rowfirst; r <= rowlast; ++r) { | - |
| 294 | | - |
| 295 | int rowp = rowY(r); | - |
| 296 | | - |
| 297 | | - |
| 298 | | - |
| 299 | | - |
| 300 | for (int c = colfirst; c <= collast; ++c) { | - |
| 301 | | - |
| 302 | int colp = columnX(c); | - |
| 303 | | - |
| 304 | rect.translate(colp, rowp); | - |
| 305 | paintCell(p, r, c, rect); | - |
| 306 | rect.translate(-colp, -rowp); | - |
| 307 | } | - |
| 308 | } | - |
| 309 | } | - |
| 310 | | - |
| 311 | QWellArray::QWellArray(int rows, int cols, QWidget *parent) | - |
| 312 | : QWidget(parent) | - |
| 313 | ,nrows(rows), ncols(cols) | - |
| 314 | { | - |
| 315 | setFocusPolicy(Qt::StrongFocus); | - |
| 316 | cellw = 28; | - |
| 317 | cellh = 24; | - |
| 318 | curCol = 0; | - |
| 319 | curRow = 0; | - |
| 320 | selCol = -1; | - |
| 321 | selRow = -1; | - |
| 322 | } | - |
| 323 | | - |
| 324 | QSize QWellArray::sizeHint() const | - |
| 325 | { | - |
| 326 | ensurePolished(); | - |
| 327 | return gridSize().boundedTo(QSize(640, 480)); | - |
| 328 | } | - |
| 329 | | - |
| 330 | | - |
| 331 | void QWellArray::paintCell(QPainter* p, int row, int col, const QRect &rect) | - |
| 332 | { | - |
| 333 | int b = 3; | - |
| 334 | | - |
| 335 | const QPalette & g = palette(); | - |
| 336 | QStyleOptionFrame opt; | - |
| 337 | int dfw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); | - |
| 338 | opt.lineWidth = dfw; | - |
| 339 | opt.midLineWidth = 1; | - |
| 340 | opt.rect = rect.adjusted(b, b, -b, -b); | - |
| 341 | opt.palette = g; | - |
| 342 | opt.state = QStyle::State_Enabled | QStyle::State_Sunken; | - |
| 343 | style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this); | - |
| 344 | b += dfw; | - |
| 345 | | - |
| 346 | if ((row == curRow) && (col == curCol)) { | - |
| 347 | if (hasFocus()) { | - |
| 348 | QStyleOptionFocusRect opt; | - |
| 349 | opt.palette = g; | - |
| 350 | opt.rect = rect; | - |
| 351 | opt.state = QStyle::State_None | QStyle::State_KeyboardFocusChange; | - |
| 352 | style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, this); | - |
| 353 | } | - |
| 354 | } | - |
| 355 | paintCellContents(p, row, col, opt.rect.adjusted(dfw, dfw, -dfw, -dfw)); | - |
| 356 | } | - |
| 357 | | - |
| 358 | | - |
| 359 | | - |
| 360 | | - |
| 361 | void QWellArray::paintCellContents(QPainter *p, int row, int col, const QRect &r) | - |
| 362 | { | - |
| 363 | Q_UNUSED(row); | - |
| 364 | Q_UNUSED(col); | - |
| 365 | p->fillRect(r, Qt::white); | - |
| 366 | p->setPen(Qt::black); | - |
| 367 | p->drawLine(r.topLeft(), r.bottomRight()); | - |
| 368 | p->drawLine(r.topRight(), r.bottomLeft()); | - |
| 369 | } | - |
| 370 | | - |
| 371 | void QWellArray::mousePressEvent(QMouseEvent *e) | - |
| 372 | { | - |
| 373 | | - |
| 374 | QPoint pos = e->pos(); | - |
| 375 | setCurrent(rowAt(pos.y()), columnAt(pos.x())); | - |
| 376 | } | - |
| 377 | | - |
| 378 | void QWellArray::mouseReleaseEvent(QMouseEvent * ) | - |
| 379 | { | - |
| 380 | | - |
| 381 | setSelected(curRow, curCol); | - |
| 382 | } | - |
| 383 | | - |
| 384 | | - |
| 385 | | - |
| 386 | | - |
| 387 | | - |
| 388 | | - |
| 389 | | - |
| 390 | void QWellArray::setCurrent(int row, int col) | - |
| 391 | { | - |
| 392 | if ((curRow == row) && (curCol == col)) | - |
| 393 | return; | - |
| 394 | | - |
| 395 | if (row < 0 || col < 0) | - |
| 396 | row = col = -1; | - |
| 397 | | - |
| 398 | int oldRow = curRow; | - |
| 399 | int oldCol = curCol; | - |
| 400 | | - |
| 401 | curRow = row; | - |
| 402 | curCol = col; | - |
| 403 | | - |
| 404 | updateCell(oldRow, oldCol); | - |
| 405 | updateCell(curRow, curCol); | - |
| 406 | | - |
| 407 | emit currentChanged(curRow, curCol); | - |
| 408 | } | - |
| 409 | | - |
| 410 | | - |
| 411 | | - |
| 412 | | - |
| 413 | | - |
| 414 | | - |
| 415 | | - |
| 416 | void QWellArray::setSelected(int row, int col) | - |
| 417 | { | - |
| 418 | int oldRow = selRow; | - |
| 419 | int oldCol = selCol; | - |
| 420 | | - |
| 421 | if (row < 0 || col < 0) | - |
| 422 | row = col = -1; | - |
| 423 | | - |
| 424 | selCol = col; | - |
| 425 | selRow = row; | - |
| 426 | | - |
| 427 | updateCell(oldRow, oldCol); | - |
| 428 | updateCell(selRow, selCol); | - |
| 429 | if (row >= 0) | - |
| 430 | emit selected(row, col); | - |
| 431 | | - |
| 432 | #ifndef QT_NO_MENU | - |
| 433 | if (isVisible() && qobject_cast<QMenu*>(parentWidget())) | - |
| 434 | parentWidget()->close(); | - |
| 435 | #endif | - |
| 436 | } | - |
| 437 | | - |
| 438 | void QWellArray::focusInEvent(QFocusEvent*) | - |
| 439 | { | - |
| 440 | updateCell(curRow, curCol); | - |
| 441 | emit currentChanged(curRow, curCol); | - |
| 442 | } | - |
| 443 | | - |
| 444 | | - |
| 445 | | - |
| 446 | | - |
| 447 | void QWellArray::focusOutEvent(QFocusEvent*) | - |
| 448 | { | - |
| 449 | updateCell(curRow, curCol); | - |
| 450 | } | - |
| 451 | | - |
| 452 | | - |
| 453 | | - |
| 454 | void QWellArray::keyPressEvent(QKeyEvent* e) | - |
| 455 | { | - |
| 456 | switch(e->key()) { | - |
| 457 | case Qt::Key_Left: | - |
| 458 | if(curCol > 0) | - |
| 459 | setCurrent(curRow, curCol - 1); | - |
| 460 | break; | - |
| 461 | case Qt::Key_Right: | - |
| 462 | if(curCol < numCols()-1) | - |
| 463 | setCurrent(curRow, curCol + 1); | - |
| 464 | break; | - |
| 465 | case Qt::Key_Up: | - |
| 466 | if(curRow > 0) | - |
| 467 | setCurrent(curRow - 1, curCol); | - |
| 468 | break; | - |
| 469 | case Qt::Key_Down: | - |
| 470 | if(curRow < numRows()-1) | - |
| 471 | setCurrent(curRow + 1, curCol); | - |
| 472 | break; | - |
| 473 | #if 0 | - |
| 474 | | - |
| 475 | case Qt::Key_Return: | - |
| 476 | case Qt::Key_Enter: | - |
| 477 | | - |
| 478 | | - |
| 479 | | - |
| 480 | | - |
| 481 | e->ignore(); | - |
| 482 | | - |
| 483 | #endif | - |
| 484 | case Qt::Key_Space: | - |
| 485 | setSelected(curRow, curCol); | - |
| 486 | break; | - |
| 487 | default: | - |
| 488 | e->ignore(); | - |
| 489 | return; | - |
| 490 | } | - |
| 491 | | - |
| 492 | } | - |
| 493 | | - |
| 494 | | - |
| 495 | | - |
| 496 | | - |
| 497 | class QColorPickingEventFilter : public QObject { | - |
| 498 | public: | - |
| 499 | explicit QColorPickingEventFilter(QColorDialogPrivate *dp, QObject *parent = 0) : QObject(parent), m_dp(dp) {} | - |
| 500 | | - |
| 501 | bool eventFilter(QObject *, QEvent *event) Q_DECL_OVERRIDE | - |
| 502 | { | - |
| 503 | switch (event->type()) { | - |
| 504 | case QEvent::MouseMove: | - |
| 505 | return m_dp->handleColorPickingMouseMove(static_cast<QMouseEvent *>(event)); | - |
| 506 | case QEvent::MouseButtonRelease: | - |
| 507 | return m_dp->handleColorPickingMouseButtonRelease(static_cast<QMouseEvent *>(event)); | - |
| 508 | case QEvent::KeyPress: | - |
| 509 | return m_dp->handleColorPickingKeyPress(static_cast<QKeyEvent *>(event)); | - |
| 510 | default: | - |
| 511 | break; | - |
| 512 | } | - |
| 513 | return false; | - |
| 514 | } | - |
| 515 | | - |
| 516 | private: | - |
| 517 | QColorDialogPrivate *m_dp; | - |
| 518 | }; | - |
| 519 | | - |
| 520 | } | - |
| 521 | | - |
| 522 | | - |
| 523 | | - |
| 524 | | - |
| 525 | | - |
| 526 | int QColorDialog::customCount() | - |
| 527 | { | - |
| 528 | return QColorDialogOptions::customColorCount(); | - |
| 529 | } | - |
| 530 | | - |
| 531 | | - |
| 532 | | - |
| 533 | | - |
| 534 | | - |
| 535 | | - |
| 536 | QColor QColorDialog::customColor(int index) | - |
| 537 | { | - |
| 538 | return QColor(QColorDialogOptions::customColor(index)); | - |
| 539 | } | - |
| 540 | | - |
| 541 | | - |
| 542 | | - |
| 543 | | - |
| 544 | | - |
| 545 | | - |
| 546 | | - |
| 547 | | - |
| 548 | void QColorDialog::setCustomColor(int index, QColor color) | - |
| 549 | { | - |
| 550 | QColorDialogOptions::setCustomColor(index, color.rgba()); | - |
| 551 | } | - |
| 552 | | - |
| 553 | | - |
| 554 | | - |
| 555 | | - |
| 556 | | - |
| 557 | | - |
| 558 | QColor QColorDialog::standardColor(int index) | - |
| 559 | { | - |
| 560 | return QColor(QColorDialogOptions::standardColor(index)); | - |
| 561 | } | - |
| 562 | | - |
| 563 | | - |
| 564 | | - |
| 565 | | - |
| 566 | | - |
| 567 | | - |
| 568 | | - |
| 569 | | - |
| 570 | void QColorDialog::setStandardColor(int index, QColor color) | - |
| 571 | { | - |
| 572 | QColorDialogOptions::setStandardColor(index, color.rgba()); | - |
| 573 | } | - |
| 574 | | - |
| 575 | static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v) | - |
| 576 | { | - |
| 577 | QColor c; | - |
| 578 | c.setRgb(rgb); | - |
| 579 | c.getHsv(&h, &s, &v); | - |
| 580 | } | - |
| 581 | | - |
| 582 | namespace { | - |
| 583 | | - |
| 584 | class QColorWell : public QWellArray | - |
| 585 | { | - |
| 586 | public: | - |
| 587 | QColorWell(QWidget *parent, int r, int c, QRgb *vals) | - |
| 588 | :QWellArray(r, c, parent), values(vals), mousePressed(false), oldCurrent(-1, -1) | - |
| 589 | { setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); } | - |
| 590 | | - |
| 591 | protected: | - |
| 592 | void paintCellContents(QPainter *, int row, int col, const QRect&) Q_DECL_OVERRIDE; | - |
| 593 | void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; | - |
| 594 | void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE; | - |
| 595 | void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE; | - |
| 596 | #ifndef QT_NO_DRAGANDDROP | - |
| 597 | void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE; | - |
| 598 | void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE; | - |
| 599 | void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE; | - |
| 600 | void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE; | - |
| 601 | #endif | - |
| 602 | | - |
| 603 | private: | - |
| 604 | QRgb *values; | - |
| 605 | bool mousePressed; | - |
| 606 | QPoint pressPos; | - |
| 607 | QPoint oldCurrent; | - |
| 608 | | - |
| 609 | }; | - |
| 610 | | - |
| 611 | void QColorWell::paintCellContents(QPainter *p, int row, int col, const QRect &r) | - |
| 612 | { | - |
| 613 | int i = row + col*numRows(); | - |
| 614 | p->fillRect(r, QColor(values[i])); | - |
| 615 | } | - |
| 616 | | - |
| 617 | void QColorWell::mousePressEvent(QMouseEvent *e) | - |
| 618 | { | - |
| 619 | oldCurrent = QPoint(selectedRow(), selectedColumn()); | - |
| 620 | QWellArray::mousePressEvent(e); | - |
| 621 | mousePressed = true; | - |
| 622 | pressPos = e->pos(); | - |
| 623 | } | - |
| 624 | | - |
| 625 | void QColorWell::mouseMoveEvent(QMouseEvent *e) | - |
| 626 | { | - |
| 627 | QWellArray::mouseMoveEvent(e); | - |
| 628 | #ifndef QT_NO_DRAGANDDROP | - |
| 629 | if (!mousePressed) | - |
| 630 | return; | - |
| 631 | if ((pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) { | - |
| 632 | setCurrent(oldCurrent.x(), oldCurrent.y()); | - |
| 633 | int i = rowAt(pressPos.y()) + columnAt(pressPos.x()) * numRows(); | - |
| 634 | QColor col(values[i]); | - |
| 635 | QMimeData *mime = new QMimeData; | - |
| 636 | mime->setColorData(col); | - |
| 637 | QPixmap pix(cellWidth(), cellHeight()); | - |
| 638 | pix.fill(col); | - |
| 639 | QPainter p(&pix); | - |
| 640 | p.drawRect(0, 0, pix.width() - 1, pix.height() - 1); | - |
| 641 | p.end(); | - |
| 642 | QDrag *drg = new QDrag(this); | - |
| 643 | drg->setMimeData(mime); | - |
| 644 | drg->setPixmap(pix); | - |
| 645 | mousePressed = false; | - |
| 646 | drg->start(); | - |
| 647 | } | - |
| 648 | #endif | - |
| 649 | } | - |
| 650 | | - |
| 651 | #ifndef QT_NO_DRAGANDDROP | - |
| 652 | void QColorWell::dragEnterEvent(QDragEnterEvent *e) | - |
| 653 | { | - |
| 654 | if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid()) | - |
| 655 | e->accept(); | - |
| 656 | else | - |
| 657 | e->ignore(); | - |
| 658 | } | - |
| 659 | | - |
| 660 | void QColorWell::dragLeaveEvent(QDragLeaveEvent *) | - |
| 661 | { | - |
| 662 | if (hasFocus()) | - |
| 663 | parentWidget()->setFocus(); | - |
| 664 | } | - |
| 665 | | - |
| 666 | void QColorWell::dragMoveEvent(QDragMoveEvent *e) | - |
| 667 | { | - |
| 668 | if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid()) { | - |
| 669 | setCurrent(rowAt(e->pos().y()), columnAt(e->pos().x())); | - |
| 670 | e->accept(); | - |
| 671 | } else { | - |
| 672 | e->ignore(); | - |
| 673 | } | - |
| 674 | } | - |
| 675 | | - |
| 676 | void QColorWell::dropEvent(QDropEvent *e) | - |
| 677 | { | - |
| 678 | QColor col = qvariant_cast<QColor>(e->mimeData()->colorData()); | - |
| 679 | if (col.isValid()) { | - |
| 680 | int i = rowAt(e->pos().y()) + columnAt(e->pos().x()) * numRows(); | - |
| 681 | values[i] = col.rgb(); | - |
| 682 | update(); | - |
| 683 | e->accept(); | - |
| 684 | } else { | - |
| 685 | e->ignore(); | - |
| 686 | } | - |
| 687 | } | - |
| 688 | | - |
| 689 | #endif // QT_NO_DRAGANDDROP | - |
| 690 | | - |
| 691 | void QColorWell::mouseReleaseEvent(QMouseEvent *e) | - |
| 692 | { | - |
| 693 | if (!mousePressed) | - |
| 694 | return; | - |
| 695 | QWellArray::mouseReleaseEvent(e); | - |
| 696 | mousePressed = false; | - |
| 697 | } | - |
| 698 | | - |
| 699 | class QColorPicker : public QFrame | - |
| 700 | { | - |
| 701 | Q_OBJECT | - |
| 702 | public: | - |
| 703 | QColorPicker(QWidget* parent); | - |
| 704 | ~QColorPicker(); | - |
| 705 | | - |
| 706 | void setCrossVisible(bool visible); | - |
| 707 | public slots: | - |
| 708 | void setCol(int h, int s); | - |
| 709 | | - |
| 710 | signals: | - |
| 711 | void newCol(int h, int s); | - |
| 712 | | - |
| 713 | protected: | - |
| 714 | QSize sizeHint() const Q_DECL_OVERRIDE; | - |
| 715 | void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; | - |
| 716 | void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; | - |
| 717 | void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; | - |
| 718 | void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; | - |
| 719 | | - |
| 720 | private: | - |
| 721 | int hue; | - |
| 722 | int sat; | - |
| 723 | | - |
| 724 | QPoint colPt(); | - |
| 725 | int huePt(const QPoint &pt); | - |
| 726 | int satPt(const QPoint &pt); | - |
| 727 | void setCol(const QPoint &pt); | - |
| 728 | | - |
| 729 | QPixmap pix; | - |
| 730 | bool crossVisible; | - |
| 731 | }; | - |
| 732 | | - |
| 733 | static int pWidth = 220; | - |
| 734 | static int pHeight = 200; | - |
| 735 | | - |
| 736 | class QColorLuminancePicker : public QWidget | - |
| 737 | { | - |
| 738 | Q_OBJECT | - |
| 739 | public: | - |
| 740 | QColorLuminancePicker(QWidget* parent=0); | - |
| 741 | ~QColorLuminancePicker(); | - |
| 742 | | - |
| 743 | public slots: | - |
| 744 | void setCol(int h, int s, int v); | - |
| 745 | void setCol(int h, int s); | - |
| 746 | | - |
| 747 | signals: | - |
| 748 | void newHsv(int h, int s, int v); | - |
| 749 | | - |
| 750 | protected: | - |
| 751 | void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; | - |
| 752 | void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; | - |
| 753 | void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; | - |
| 754 | | - |
| 755 | private: | - |
| 756 | enum { foff = 3, coff = 4 }; | - |
| 757 | int val; | - |
| 758 | int hue; | - |
| 759 | int sat; | - |
| 760 | | - |
| 761 | int y2val(int y); | - |
| 762 | int val2y(int val); | - |
| 763 | void setVal(int v); | - |
| 764 | | - |
| 765 | QPixmap *pix; | - |
| 766 | }; | - |
| 767 | | - |
| 768 | | - |
| 769 | int QColorLuminancePicker::y2val(int y) | - |
| 770 | { | - |
| 771 | int d = height() - 2*coff - 1; | - |
| 772 | return 255 - (y - coff)*255/d; | - |
| 773 | } | - |
| 774 | | - |
| 775 | int QColorLuminancePicker::val2y(int v) | - |
| 776 | { | - |
| 777 | int d = height() - 2*coff - 1; | - |
| 778 | return coff + (255-v)*d/255; | - |
| 779 | } | - |
| 780 | | - |
| 781 | QColorLuminancePicker::QColorLuminancePicker(QWidget* parent) | - |
| 782 | :QWidget(parent) | - |
| 783 | { | - |
| 784 | hue = 100; val = 100; sat = 100; | - |
| 785 | pix = 0; | - |
| 786 | | - |
| 787 | } | - |
| 788 | | - |
| 789 | QColorLuminancePicker::~QColorLuminancePicker() | - |
| 790 | { | - |
| 791 | delete pix; | - |
| 792 | } | - |
| 793 | | - |
| 794 | void QColorLuminancePicker::mouseMoveEvent(QMouseEvent *m) | - |
| 795 | { | - |
| 796 | setVal(y2val(m->y())); | - |
| 797 | } | - |
| 798 | void QColorLuminancePicker::mousePressEvent(QMouseEvent *m) | - |
| 799 | { | - |
| 800 | setVal(y2val(m->y())); | - |
| 801 | } | - |
| 802 | | - |
| 803 | void QColorLuminancePicker::setVal(int v) | - |
| 804 | { | - |
| 805 | if (val == v) | - |
| 806 | return; | - |
| 807 | val = qMax(0, qMin(v,255)); | - |
| 808 | delete pix; pix=0; | - |
| 809 | repaint(); | - |
| 810 | emit newHsv(hue, sat, val); | - |
| 811 | } | - |
| 812 | | - |
| 813 | | - |
| 814 | void QColorLuminancePicker::setCol(int h, int s) | - |
| 815 | { | - |
| 816 | setCol(h, s, val); | - |
| 817 | emit newHsv(h, s, val); | - |
| 818 | } | - |
| 819 | | - |
| 820 | void QColorLuminancePicker::paintEvent(QPaintEvent *) | - |
| 821 | { | - |
| 822 | int w = width() - 5; | - |
| 823 | | - |
| 824 | QRect r(0, foff, w, height() - 2*foff); | - |
| 825 | int wi = r.width() - 2; | - |
| 826 | int hi = r.height() - 2; | - |
| 827 | if (!pix || pix->height() != hi || pix->width() != wi) { | - |
| 828 | delete pix; | - |
| 829 | QImage img(wi, hi, QImage::Format_RGB32); | - |
| 830 | int y; | - |
| 831 | uint *pixel = (uint *) img.scanLine(0); | - |
| 832 | for (y = 0; y < hi; y++) { | - |
| 833 | uint *end = pixel + wi; | - |
| 834 | std::fill(pixel, end, QColor::fromHsv(hue, sat, y2val(y + coff)).rgb()); | - |
| 835 | pixel = end; | - |
| 836 | } | - |
| 837 | pix = new QPixmap(QPixmap::fromImage(img)); | - |
| 838 | } | - |
| 839 | QPainter p(this); | - |
| 840 | p.drawPixmap(1, coff, *pix); | - |
| 841 | const QPalette &g = palette(); | - |
| 842 | qDrawShadePanel(&p, r, g, true); | - |
| 843 | p.setPen(g.foreground().color()); | - |
| 844 | p.setBrush(g.foreground()); | - |
| 845 | QPolygon a; | - |
| 846 | int y = val2y(val); | - |
| 847 | a.setPoints(3, w, y, w+5, y+5, w+5, y-5); | - |
| 848 | p.eraseRect(w, 0, 5, height()); | - |
| 849 | p.drawPolygon(a); | - |
| 850 | } | - |
| 851 | | - |
| 852 | void QColorLuminancePicker::setCol(int h, int s , int v) | - |
| 853 | { | - |
| 854 | val = v; | - |
| 855 | hue = h; | - |
| 856 | sat = s; | - |
| 857 | delete pix; pix=0; | - |
| 858 | repaint(); | - |
| 859 | } | - |
| 860 | | - |
| 861 | QPoint QColorPicker::colPt() | - |
| 862 | { | - |
| 863 | QRect r = contentsRect(); | - |
| 864 | return QPoint((360 - hue) * (r.width() - 1) / 360, (255 - sat) * (r.height() - 1) / 255); | - |
| 865 | } | - |
| 866 | | - |
| 867 | int QColorPicker::huePt(const QPoint &pt) | - |
| 868 | { | - |
| 869 | QRect r = contentsRect(); | - |
| 870 | return 360 - pt.x() * 360 / (r.width() - 1); | - |
| 871 | } | - |
| 872 | | - |
| 873 | int QColorPicker::satPt(const QPoint &pt) | - |
| 874 | { | - |
| 875 | QRect r = contentsRect(); | - |
| 876 | return 255 - pt.y() * 255 / (r.height() - 1); | - |
| 877 | } | - |
| 878 | | - |
| 879 | void QColorPicker::setCol(const QPoint &pt) | - |
| 880 | { | - |
| 881 | setCol(huePt(pt), satPt(pt)); | - |
| 882 | } | - |
| 883 | | - |
| 884 | QColorPicker::QColorPicker(QWidget* parent) | - |
| 885 | : QFrame(parent) | - |
| 886 | , crossVisible(true) | - |
| 887 | { | - |
| 888 | hue = 0; sat = 0; | - |
| 889 | setCol(150, 255); | - |
| 890 | | - |
| 891 | setAttribute(Qt::WA_NoSystemBackground); | - |
| 892 | setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) ); | - |
| 893 | } | - |
| 894 | | - |
| 895 | QColorPicker::~QColorPicker() | - |
| 896 | { | - |
| 897 | } | - |
| 898 | | - |
| 899 | void QColorPicker::setCrossVisible(bool visible) | - |
| 900 | { | - |
| 901 | if (crossVisible != visible) { | - |
| 902 | crossVisible = visible; | - |
| 903 | update(); | - |
| 904 | } | - |
| 905 | } | - |
| 906 | | - |
| 907 | QSize QColorPicker::sizeHint() const | - |
| 908 | { | - |
| 909 | return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth()); | - |
| 910 | } | - |
| 911 | | - |
| 912 | void QColorPicker::setCol(int h, int s) | - |
| 913 | { | - |
| 914 | int nhue = qMin(qMax(0,h), 359); | - |
| 915 | int nsat = qMin(qMax(0,s), 255); | - |
| 916 | if (nhue == hue && nsat == sat) | - |
| 917 | return; | - |
| 918 | | - |
| 919 | QRect r(colPt(), QSize(20,20)); | - |
| 920 | hue = nhue; sat = nsat; | - |
| 921 | r = r.united(QRect(colPt(), QSize(20,20))); | - |
| 922 | r.translate(contentsRect().x()-9, contentsRect().y()-9); | - |
| 923 | | - |
| 924 | repaint(r); | - |
| 925 | } | - |
| 926 | | - |
| 927 | void QColorPicker::mouseMoveEvent(QMouseEvent *m) | - |
| 928 | { | - |
| 929 | QPoint p = m->pos() - contentsRect().topLeft(); | - |
| 930 | setCol(p); | - |
| 931 | emit newCol(hue, sat); | - |
| 932 | } | - |
| 933 | | - |
| 934 | void QColorPicker::mousePressEvent(QMouseEvent *m) | - |
| 935 | { | - |
| 936 | QPoint p = m->pos() - contentsRect().topLeft(); | - |
| 937 | setCol(p); | - |
| 938 | emit newCol(hue, sat); | - |
| 939 | } | - |
| 940 | | - |
| 941 | void QColorPicker::paintEvent(QPaintEvent* ) | - |
| 942 | { | - |
| 943 | QPainter p(this); | - |
| 944 | drawFrame(&p); | - |
| 945 | QRect r = contentsRect(); | - |
| 946 | | - |
| 947 | p.drawPixmap(r.topLeft(), pix); | - |
| 948 | | - |
| 949 | if (crossVisible) { | - |
| 950 | QPoint pt = colPt() + r.topLeft(); | - |
| 951 | p.setPen(Qt::black); | - |
| 952 | p.fillRect(pt.x()-9, pt.y(), 20, 2, Qt::black); | - |
| 953 | p.fillRect(pt.x(), pt.y()-9, 2, 20, Qt::black); | - |
| 954 | } | - |
| 955 | } | - |
| 956 | | - |
| 957 | void QColorPicker::resizeEvent(QResizeEvent *ev) | - |
| 958 | { | - |
| 959 | QFrame::resizeEvent(ev); | - |
| 960 | | - |
| 961 | int w = width() - frameWidth() * 2; | - |
| 962 | int h = height() - frameWidth() * 2; | - |
| 963 | QImage img(w, h, QImage::Format_RGB32); | - |
| 964 | int x, y; | - |
| 965 | uint *pixel = (uint *) img.scanLine(0); | - |
| 966 | for (y = 0; y < h; y++) { | - |
| 967 | const uint *end = pixel + w; | - |
| 968 | x = 0; | - |
| 969 | while (pixel < end) { | - |
| 970 | QPoint p(x, y); | - |
| 971 | QColor c; | - |
| 972 | c.setHsv(huePt(p), satPt(p), 200); | - |
| 973 | *pixel = c.rgb(); | - |
| 974 | ++pixel; | - |
| 975 | ++x; | - |
| 976 | } | - |
| 977 | } | - |
| 978 | pix = QPixmap::fromImage(img); | - |
| 979 | } | - |
| 980 | | - |
| 981 | | - |
| 982 | class QColSpinBox : public QSpinBox | - |
| 983 | { | - |
| 984 | public: | - |
| 985 | QColSpinBox(QWidget *parent) | - |
| 986 | : QSpinBox(parent) { setRange(0, 255); } | - |
| 987 | void setValue(int i) { | - |
| 988 | const QSignalBlocker blocker(this); | - |
| 989 | QSpinBox::setValue(i); | - |
| 990 | } | - |
| 991 | }; | - |
| 992 | | - |
| 993 | class QColorShowLabel; | - |
| 994 | | - |
| 995 | class QColorShower : public QWidget | - |
| 996 | { | - |
| 997 | Q_OBJECT | - |
| 998 | public: | - |
| 999 | QColorShower(QColorDialog *parent); | - |
| 1000 | | - |
| 1001 | | - |
| 1002 | void setHsv(int h, int s, int v); | - |
| 1003 | | - |
| 1004 | int currentAlpha() const | - |
| 1005 | { return (colorDialog->options() & QColorDialog::ShowAlphaChannel) ? alphaEd->value() : 255; } | - |
| 1006 | void setCurrentAlpha(int a) { alphaEd->setValue(a); rgbEd(); } | - |
| 1007 | void showAlpha(bool b); | - |
| 1008 | bool isAlphaVisible() const; | - |
| 1009 | | - |
| 1010 | QRgb currentColor() const { return curCol; } | - |
| 1011 | QColor currentQColor() const { return curQColor; } | - |
| 1012 | void retranslateStrings(); | - |
| 1013 | void updateQColor(); | - |
| 1014 | | - |
| 1015 | public slots: | - |
| 1016 | void setRgb(QRgb rgb); | - |
| 1017 | | - |
| 1018 | signals: | - |
| 1019 | void newCol(QRgb rgb); | - |
| 1020 | void currentColorChanged(const QColor &color); | - |
| 1021 | | - |
| 1022 | private slots: | - |
| 1023 | void rgbEd(); | - |
| 1024 | void hsvEd(); | - |
| 1025 | void htmlEd(); | - |
| 1026 | | - |
| 1027 | private: | - |
| 1028 | void showCurrentColor(); | - |
| 1029 | int hue, sat, val; | - |
| 1030 | QRgb curCol; | - |
| 1031 | QColor curQColor; | - |
| 1032 | QLabel *lblHue; | - |
| 1033 | QLabel *lblSat; | - |
| 1034 | QLabel *lblVal; | - |
| 1035 | QLabel *lblRed; | - |
| 1036 | QLabel *lblGreen; | - |
| 1037 | QLabel *lblBlue; | - |
| 1038 | QLabel *lblHtml; | - |
| 1039 | QColSpinBox *hEd; | - |
| 1040 | QColSpinBox *sEd; | - |
| 1041 | QColSpinBox *vEd; | - |
| 1042 | QColSpinBox *rEd; | - |
| 1043 | QColSpinBox *gEd; | - |
| 1044 | QColSpinBox *bEd; | - |
| 1045 | QColSpinBox *alphaEd; | - |
| 1046 | QLabel *alphaLab; | - |
| 1047 | QLineEdit *htEd; | - |
| 1048 | QColorShowLabel *lab; | - |
| 1049 | bool rgbOriginal; | - |
| 1050 | QColorDialog *colorDialog; | - |
| 1051 | QGridLayout *gl; | - |
| 1052 | | - |
| 1053 | friend class QT_PREPEND_NAMESPACE(QColorDialog); | - |
| 1054 | friend class QT_PREPEND_NAMESPACE(QColorDialogPrivate); | - |
| 1055 | }; | - |
| 1056 | | - |
| 1057 | class QColorShowLabel : public QFrame | - |
| 1058 | { | - |
| 1059 | Q_OBJECT | - |
| 1060 | | - |
| 1061 | public: | - |
| 1062 | QColorShowLabel(QWidget *parent) : QFrame(parent) { | - |
| 1063 | setFrameStyle(QFrame::Panel|QFrame::Sunken); | - |
| 1064 | setAcceptDrops(true); | - |
| 1065 | mousePressed = false; | - |
| 1066 | } | - |
| 1067 | void setColor(QColor c) { col = c; } | - |
| 1068 | | - |
| 1069 | signals: | - |
| 1070 | void colorDropped(QRgb); | - |
| 1071 | | - |
| 1072 | protected: | - |
| 1073 | void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; | - |
| 1074 | void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; | - |
| 1075 | void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE; | - |
| 1076 | void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE; | - |
| 1077 | #ifndef QT_NO_DRAGANDDROP | - |
| 1078 | void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE; | - |
| 1079 | void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE; | - |
| 1080 | void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE; | - |
| 1081 | #endif | - |
| 1082 | | - |
| 1083 | private: | - |
| 1084 | QColor col; | - |
| 1085 | bool mousePressed; | - |
| 1086 | QPoint pressPos; | - |
| 1087 | }; | - |
| 1088 | | - |
| 1089 | void QColorShowLabel::paintEvent(QPaintEvent *e) | - |
| 1090 | { | - |
| 1091 | QPainter p(this); | - |
| 1092 | drawFrame(&p); | - |
| 1093 | p.fillRect(contentsRect()&e->rect(), col); | - |
| 1094 | } | - |
| 1095 | | - |
| 1096 | void QColorShower::showAlpha(bool b) | - |
| 1097 | { | - |
| 1098 | alphaLab->setVisible(b); | - |
| 1099 | alphaEd->setVisible(b); | - |
| 1100 | } | - |
| 1101 | | - |
| 1102 | inline bool QColorShower::isAlphaVisible() const | - |
| 1103 | { | - |
| 1104 | return alphaLab->isVisible(); | - |
| 1105 | } | - |
| 1106 | | - |
| 1107 | void QColorShowLabel::mousePressEvent(QMouseEvent *e) | - |
| 1108 | { | - |
| 1109 | mousePressed = true; | - |
| 1110 | pressPos = e->pos(); | - |
| 1111 | } | - |
| 1112 | | - |
| 1113 | void QColorShowLabel::mouseMoveEvent(QMouseEvent *e) | - |
| 1114 | { | - |
| 1115 | #ifdef QT_NO_DRAGANDDROP | - |
| 1116 | Q_UNUSED(e); | - |
| 1117 | #else | - |
| 1118 | if (!mousePressed) | - |
| 1119 | return; | - |
| 1120 | if ((pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) { | - |
| 1121 | QMimeData *mime = new QMimeData; | - |
| 1122 | mime->setColorData(col); | - |
| 1123 | QPixmap pix(30, 20); | - |
| 1124 | pix.fill(col); | - |
| 1125 | QPainter p(&pix); | - |
| 1126 | p.drawRect(0, 0, pix.width() - 1, pix.height() - 1); | - |
| 1127 | p.end(); | - |
| 1128 | QDrag *drg = new QDrag(this); | - |
| 1129 | drg->setMimeData(mime); | - |
| 1130 | drg->setPixmap(pix); | - |
| 1131 | mousePressed = false; | - |
| 1132 | drg->start(); | - |
| 1133 | } | - |
| 1134 | #endif | - |
| 1135 | } | - |
| 1136 | | - |
| 1137 | #ifndef QT_NO_DRAGANDDROP | - |
| 1138 | void QColorShowLabel::dragEnterEvent(QDragEnterEvent *e) | - |
| 1139 | { | - |
| 1140 | if (qvariant_cast<QColor>(e->mimeData()->colorData()).isValid()) | - |
| 1141 | e->accept(); | - |
| 1142 | else | - |
| 1143 | e->ignore(); | - |
| 1144 | } | - |
| 1145 | | - |
| 1146 | void QColorShowLabel::dragLeaveEvent(QDragLeaveEvent *) | - |
| 1147 | { | - |
| 1148 | } | - |
| 1149 | | - |
| 1150 | void QColorShowLabel::dropEvent(QDropEvent *e) | - |
| 1151 | { | - |
| 1152 | QColor color = qvariant_cast<QColor>(e->mimeData()->colorData()); | - |
| 1153 | if (color.isValid()) { | - |
| 1154 | col = color; | - |
| 1155 | repaint(); | - |
| 1156 | emit colorDropped(col.rgb()); | - |
| 1157 | e->accept(); | - |
| 1158 | } else { | - |
| 1159 | e->ignore(); | - |
| 1160 | } | - |
| 1161 | } | - |
| 1162 | #endif // QT_NO_DRAGANDDROP | - |
| 1163 | | - |
| 1164 | void QColorShowLabel::mouseReleaseEvent(QMouseEvent *) | - |
| 1165 | { | - |
| 1166 | if (!mousePressed) | - |
| 1167 | return; | - |
| 1168 | mousePressed = false; | - |
| 1169 | } | - |
| 1170 | | - |
| 1171 | QColorShower::QColorShower(QColorDialog *parent) | - |
| 1172 | : QWidget(parent) | - |
| 1173 | { | - |
| 1174 | colorDialog = parent; | - |
| 1175 | | - |
| 1176 | curCol = qRgb(255, 255, 255); | - |
| 1177 | curQColor = Qt::white; | - |
| 1178 | | - |
| 1179 | gl = new QGridLayout(this); | - |
| 1180 | gl->setMargin(gl->spacing()); | - |
| 1181 | lab = new QColorShowLabel(this); | - |
| 1182 | | - |
| 1183 | #ifndef Q_OS_WINCE | - |
| 1184 | #ifdef QT_SMALL_COLORDIALOG | - |
| 1185 | lab->setMinimumHeight(60); | - |
| 1186 | #endif | - |
| 1187 | lab->setMinimumWidth(60); | - |
| 1188 | #else | - |
| 1189 | lab->setMinimumWidth(20); | - |
| 1190 | #endif | - |
| 1191 | | - |
| 1192 | | - |
| 1193 | | - |
| 1194 | #if !defined(QT_SMALL_COLORDIALOG) | - |
| 1195 | gl->addWidget(lab, 0, 0, -1, 1); | - |
| 1196 | #else | - |
| 1197 | gl->addWidget(lab, 0, 0, 1, -1); | - |
| 1198 | #endif | - |
| 1199 | connect(lab, SIGNAL(colorDropped(QRgb)), this, SIGNAL(newCol(QRgb))); | - |
| 1200 | connect(lab, SIGNAL(colorDropped(QRgb)), this, SLOT(setRgb(QRgb))); | - |
| 1201 | | - |
| 1202 | hEd = new QColSpinBox(this); | - |
| 1203 | hEd->setRange(0, 359); | - |
| 1204 | lblHue = new QLabel(this); | - |
| 1205 | #ifndef QT_NO_SHORTCUT | - |
| 1206 | lblHue->setBuddy(hEd); | - |
| 1207 | #endif | - |
| 1208 | lblHue->setAlignment(Qt::AlignRight|Qt::AlignVCenter); | - |
| 1209 | #if !defined(QT_SMALL_COLORDIALOG) | - |
| 1210 | gl->addWidget(lblHue, 0, 1); | - |
| 1211 | gl->addWidget(hEd, 0, 2); | - |
| 1212 | #else | - |
| 1213 | gl->addWidget(lblHue, 1, 0); | - |
| 1214 | gl->addWidget(hEd, 2, 0); | - |
| 1215 | #endif | - |
| 1216 | | - |
| 1217 | sEd = new QColSpinBox(this); | - |
| 1218 | lblSat = new QLabel(this); | - |
| 1219 | #ifndef QT_NO_SHORTCUT | - |
| 1220 | lblSat->setBuddy(sEd); | - |
| 1221 | #endif | - |
| 1222 | lblSat->setAlignment(Qt::AlignRight|Qt::AlignVCenter); | - |
| 1223 | #if !defined(QT_SMALL_COLORDIALOG) | - |
| 1224 | gl->addWidget(lblSat, 1, 1); | - |
| 1225 | gl->addWidget(sEd, 1, 2); | - |
| 1226 | #else | - |
| 1227 | gl->addWidget(lblSat, 1, 1); | - |
| 1228 | gl->addWidget(sEd, 2, 1); | - |
| 1229 | #endif | - |
| 1230 | | - |
| 1231 | vEd = new QColSpinBox(this); | - |
| 1232 | lblVal = new QLabel(this); | - |
| 1233 | #ifndef QT_NO_SHORTCUT | - |
| 1234 | lblVal->setBuddy(vEd); | - |
| 1235 | #endif | - |
| 1236 | lblVal->setAlignment(Qt::AlignRight|Qt::AlignVCenter); | - |
| 1237 | #if !defined(QT_SMALL_COLORDIALOG) | - |
| 1238 | gl->addWidget(lblVal, 2, 1); | - |
| 1239 | gl->addWidget(vEd, 2, 2); | - |
| 1240 | #else | - |
| 1241 | gl->addWidget(lblVal, 1, 2); | - |
| 1242 | gl->addWidget(vEd, 2, 2); | - |
| 1243 | #endif | - |
| 1244 | | - |
| 1245 | rEd = new QColSpinBox(this); | - |
| 1246 | lblRed = new QLabel(this); | - |
| 1247 | #ifndef QT_NO_SHORTCUT | - |
| 1248 | lblRed->setBuddy(rEd); | - |
| 1249 | #endif | - |
| 1250 | lblRed->setAlignment(Qt::AlignRight|Qt::AlignVCenter); | - |
| 1251 | #if !defined(QT_SMALL_COLORDIALOG) | - |
| 1252 | gl->addWidget(lblRed, 0, 3); | - |
| 1253 | gl->addWidget(rEd, 0, 4); | - |
| 1254 | #else | - |
| 1255 | gl->addWidget(lblRed, 3, 0); | - |
| 1256 | gl->addWidget(rEd, 4, 0); | - |
| 1257 | #endif | - |
| 1258 | | - |
| 1259 | gEd = new QColSpinBox(this); | - |
| 1260 | lblGreen = new QLabel(this); | - |
| 1261 | #ifndef QT_NO_SHORTCUT | - |
| 1262 | lblGreen->setBuddy(gEd); | - |
| 1263 | #endif | - |
| 1264 | lblGreen->setAlignment(Qt::AlignRight|Qt::AlignVCenter); | - |
| 1265 | #if !defined(QT_SMALL_COLORDIALOG) | - |
| 1266 | gl->addWidget(lblGreen, 1, 3); | - |
| 1267 | gl->addWidget(gEd, 1, 4); | - |
| 1268 | #else | - |
| 1269 | gl->addWidget(lblGreen, 3, 1); | - |
| 1270 | gl->addWidget(gEd, 4, 1); | - |
| 1271 | #endif | - |
| 1272 | | - |
| 1273 | bEd = new QColSpinBox(this); | - |
| 1274 | lblBlue = new QLabel(this); | - |
| 1275 | #ifndef QT_NO_SHORTCUT | - |
| 1276 | lblBlue->setBuddy(bEd); | - |
| 1277 | #endif | - |
| 1278 | lblBlue->setAlignment(Qt::AlignRight|Qt::AlignVCenter); | - |
| 1279 | #if !defined(QT_SMALL_COLORDIALOG) | - |
| 1280 | gl->addWidget(lblBlue, 2, 3); | - |
| 1281 | gl->addWidget(bEd, 2, 4); | - |
| 1282 | #else | - |
| 1283 | gl->addWidget(lblBlue, 3, 2); | - |
| 1284 | gl->addWidget(bEd, 4, 2); | - |
| 1285 | #endif | - |
| 1286 | | - |
| 1287 | alphaEd = new QColSpinBox(this); | - |
| 1288 | alphaLab = new QLabel(this); | - |
| 1289 | #ifndef QT_NO_SHORTCUT | - |
| 1290 | alphaLab->setBuddy(alphaEd); | - |
| 1291 | #endif | - |
| 1292 | alphaLab->setAlignment(Qt::AlignRight|Qt::AlignVCenter); | - |
| 1293 | #if !defined(QT_SMALL_COLORDIALOG) | - |
| 1294 | gl->addWidget(alphaLab, 3, 1, 1, 3); | - |
| 1295 | gl->addWidget(alphaEd, 3, 4); | - |
| 1296 | #else | - |
| 1297 | gl->addWidget(alphaLab, 1, 3, 3, 1); | - |
| 1298 | gl->addWidget(alphaEd, 4, 3); | - |
| 1299 | #endif | - |
| 1300 | alphaEd->hide(); | - |
| 1301 | alphaLab->hide(); | - |
| 1302 | lblHtml = new QLabel(this); | - |
| 1303 | htEd = new QLineEdit(this); | - |
| 1304 | #ifndef QT_NO_SHORTCUT | - |
| 1305 | lblHtml->setBuddy(htEd); | - |
| 1306 | #endif | - |
| 1307 | | - |
| 1308 | #if !defined(QT_NO_REGULAREXPRESSION) | - |
| 1309 | QRegularExpression regExp(QStringLiteral("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})")); | - |
| 1310 | QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this); | - |
| 1311 | htEd->setValidator(validator); | - |
| 1312 | #elif !defined(QT_NO_REGEXP) | - |
| 1313 | QRegExp regExp(QStringLiteral("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})")); | - |
| 1314 | QRegExpValidator *validator = new QRegExpValidator(regExp, this); | - |
| 1315 | htEd->setValidator(validator); | - |
| 1316 | #else | - |
| 1317 | htEd->setReadOnly(true); | - |
| 1318 | #endif | - |
| 1319 | htEd->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); | - |
| 1320 | | - |
| 1321 | lblHtml->setAlignment(Qt::AlignRight|Qt::AlignVCenter); | - |
| 1322 | #if defined(QT_SMALL_COLORDIALOG) | - |
| 1323 | gl->addWidget(lblHtml, 5, 0); | - |
| 1324 | gl->addWidget(htEd, 5, 1, 1, 2); | - |
| 1325 | #else | - |
| 1326 | gl->addWidget(lblHtml, 5, 1); | - |
| 1327 | gl->addWidget(htEd, 5, 2, 1, 3); | - |
| 1328 | #endif | - |
| 1329 | | - |
| 1330 | connect(hEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd())); | - |
| 1331 | connect(sEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd())); | - |
| 1332 | connect(vEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd())); | - |
| 1333 | | - |
| 1334 | connect(rEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd())); | - |
| 1335 | connect(gEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd())); | - |
| 1336 | connect(bEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd())); | - |
| 1337 | connect(alphaEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd())); | - |
| 1338 | connect(htEd, SIGNAL(textEdited(QString)), this, SLOT(htmlEd())); | - |
| 1339 | | - |
| 1340 | retranslateStrings(); | - |
| 1341 | } | - |
| 1342 | | - |
| 1343 | } | - |
| 1344 | | - |
| 1345 | inline QRgb QColorDialogPrivate::currentColor() const { return cs->currentColor(); } | - |
| 1346 | inline int QColorDialogPrivate::currentAlpha() const { return cs->currentAlpha(); } | - |
| 1347 | inline void QColorDialogPrivate::setCurrentAlpha(int a) { cs->setCurrentAlpha(a); } | - |
| 1348 | inline void QColorDialogPrivate::showAlpha(bool b) { cs->showAlpha(b); } | - |
| 1349 | inline bool QColorDialogPrivate::isAlphaVisible() const { return cs->isAlphaVisible(); } | - |
| 1350 | | - |
| 1351 | QColor QColorDialogPrivate::currentQColor() const | - |
| 1352 | { | - |
| 1353 | if (nativeDialogInUse) | - |
| 1354 | return platformColorDialogHelper()->currentColor(); | - |
| 1355 | return cs->currentQColor(); | - |
| 1356 | } | - |
| 1357 | | - |
| 1358 | void QColorShower::showCurrentColor() | - |
| 1359 | { | - |
| 1360 | lab->setColor(currentColor()); | - |
| 1361 | lab->repaint(); | - |
| 1362 | } | - |
| 1363 | | - |
| 1364 | void QColorShower::rgbEd() | - |
| 1365 | { | - |
| 1366 | rgbOriginal = true; | - |
| 1367 | curCol = qRgba(rEd->value(), gEd->value(), bEd->value(), currentAlpha()); | - |
| 1368 | | - |
| 1369 | rgb2hsv(currentColor(), hue, sat, val); | - |
| 1370 | | - |
| 1371 | hEd->setValue(hue); | - |
| 1372 | sEd->setValue(sat); | - |
| 1373 | vEd->setValue(val); | - |
| 1374 | | - |
| 1375 | htEd->setText(QColor(curCol).name()); | - |
| 1376 | | - |
| 1377 | showCurrentColor(); | - |
| 1378 | emit newCol(currentColor()); | - |
| 1379 | updateQColor(); | - |
| 1380 | } | - |
| 1381 | | - |
| 1382 | void QColorShower::hsvEd() | - |
| 1383 | { | - |
| 1384 | rgbOriginal = false; | - |
| 1385 | hue = hEd->value(); | - |
| 1386 | sat = sEd->value(); | - |
| 1387 | val = vEd->value(); | - |
| 1388 | | - |
| 1389 | QColor c; | - |
| 1390 | c.setHsv(hue, sat, val); | - |
| 1391 | curCol = c.rgb(); | - |
| 1392 | | - |
| 1393 | rEd->setValue(qRed(currentColor())); | - |
| 1394 | gEd->setValue(qGreen(currentColor())); | - |
| 1395 | bEd->setValue(qBlue(currentColor())); | - |
| 1396 | | - |
| 1397 | htEd->setText(c.name()); | - |
| 1398 | | - |
| 1399 | showCurrentColor(); | - |
| 1400 | emit newCol(currentColor()); | - |
| 1401 | updateQColor(); | - |
| 1402 | } | - |
| 1403 | | - |
| 1404 | void QColorShower::htmlEd() | - |
| 1405 | { | - |
| 1406 | QColor c; | - |
| 1407 | QString t = htEd->text(); | - |
| 1408 | c.setNamedColor(t); | - |
| 1409 | if (!c.isValid()) | - |
| 1410 | return; | - |
| 1411 | curCol = qRgba(c.red(), c.green(), c.blue(), currentAlpha()); | - |
| 1412 | rgb2hsv(curCol, hue, sat, val); | - |
| 1413 | | - |
| 1414 | hEd->setValue(hue); | - |
| 1415 | sEd->setValue(sat); | - |
| 1416 | vEd->setValue(val); | - |
| 1417 | | - |
| 1418 | rEd->setValue(qRed(currentColor())); | - |
| 1419 | gEd->setValue(qGreen(currentColor())); | - |
| 1420 | bEd->setValue(qBlue(currentColor())); | - |
| 1421 | | - |
| 1422 | showCurrentColor(); | - |
| 1423 | emit newCol(currentColor()); | - |
| 1424 | updateQColor(); | - |
| 1425 | } | - |
| 1426 | | - |
| 1427 | void QColorShower::setRgb(QRgb rgb) | - |
| 1428 | { | - |
| 1429 | rgbOriginal = true; | - |
| 1430 | curCol = rgb; | - |
| 1431 | | - |
| 1432 | rgb2hsv(currentColor(), hue, sat, val); | - |
| 1433 | | - |
| 1434 | hEd->setValue(hue); | - |
| 1435 | sEd->setValue(sat); | - |
| 1436 | vEd->setValue(val); | - |
| 1437 | | - |
| 1438 | rEd->setValue(qRed(currentColor())); | - |
| 1439 | gEd->setValue(qGreen(currentColor())); | - |
| 1440 | bEd->setValue(qBlue(currentColor())); | - |
| 1441 | | - |
| 1442 | htEd->setText(QColor(rgb).name()); | - |
| 1443 | | - |
| 1444 | showCurrentColor(); | - |
| 1445 | updateQColor(); | - |
| 1446 | } | - |
| 1447 | | - |
| 1448 | void QColorShower::setHsv(int h, int s, int v) | - |
| 1449 | { | - |
| 1450 | if (h < -1 || (uint)s > 255 || (uint)v > 255) | - |
| 1451 | return; | - |
| 1452 | | - |
| 1453 | rgbOriginal = false; | - |
| 1454 | hue = h; val = v; sat = s; | - |
| 1455 | QColor c; | - |
| 1456 | c.setHsv(hue, sat, val); | - |
| 1457 | curCol = c.rgb(); | - |
| 1458 | | - |
| 1459 | hEd->setValue(hue); | - |
| 1460 | sEd->setValue(sat); | - |
| 1461 | vEd->setValue(val); | - |
| 1462 | | - |
| 1463 | rEd->setValue(qRed(currentColor())); | - |
| 1464 | gEd->setValue(qGreen(currentColor())); | - |
| 1465 | bEd->setValue(qBlue(currentColor())); | - |
| 1466 | | - |
| 1467 | htEd->setText(c.name()); | - |
| 1468 | | - |
| 1469 | showCurrentColor(); | - |
| 1470 | updateQColor(); | - |
| 1471 | } | - |
| 1472 | | - |
| 1473 | void QColorShower::retranslateStrings() | - |
| 1474 | { | - |
| 1475 | lblHue->setText(QColorDialog::tr("Hu&e:")); | - |
| 1476 | lblSat->setText(QColorDialog::tr("&Sat:")); | - |
| 1477 | lblVal->setText(QColorDialog::tr("&Val:")); | - |
| 1478 | lblRed->setText(QColorDialog::tr("&Red:")); | - |
| 1479 | lblGreen->setText(QColorDialog::tr("&Green:")); | - |
| 1480 | lblBlue->setText(QColorDialog::tr("Bl&ue:")); | - |
| 1481 | alphaLab->setText(QColorDialog::tr("A&lpha channel:")); | - |
| 1482 | lblHtml->setText(QColorDialog::tr("&HTML:")); | - |
| 1483 | } | - |
| 1484 | | - |
| 1485 | void QColorShower::updateQColor() | - |
| 1486 | { | - |
| 1487 | QColor oldQColor(curQColor); | - |
| 1488 | curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), currentAlpha())); | - |
| 1489 | if (curQColor != oldQColor) | - |
| 1490 | emit currentColorChanged(curQColor); | - |
| 1491 | } | - |
| 1492 | | - |
| 1493 | | - |
| 1494 | void QColorDialogPrivate::_q_newHsv(int h, int s, int v) | - |
| 1495 | { | - |
| 1496 | if (!nativeDialogInUse) { | - |
| 1497 | cs->setHsv(h, s, v); | - |
| 1498 | cp->setCol(h, s); | - |
| 1499 | lp->setCol(h, s, v); | - |
| 1500 | } | - |
| 1501 | } | - |
| 1502 | | - |
| 1503 | | - |
| 1504 | void QColorDialogPrivate::setCurrentRgbColor(QRgb rgb) | - |
| 1505 | { | - |
| 1506 | if (!nativeDialogInUse) { | - |
| 1507 | cs->setRgb(rgb); | - |
| 1508 | _q_newColorTypedIn(rgb); | - |
| 1509 | } | - |
| 1510 | } | - |
| 1511 | | - |
| 1512 | | - |
| 1513 | void QColorDialogPrivate::setCurrentQColor(const QColor &color) | - |
| 1514 | { | - |
| 1515 | Q_Q(QColorDialog); | - |
| 1516 | if (cs->curQColor != color) { | - |
| 1517 | cs->curQColor = color; | - |
| 1518 | emit q->currentColorChanged(color); | - |
| 1519 | } | - |
| 1520 | } | - |
| 1521 | | - |
| 1522 | | - |
| 1523 | enum { | - |
| 1524 | colorColumns = 8, | - |
| 1525 | standardColorRows = 6, | - |
| 1526 | customColorRows = 2 | - |
| 1527 | }; | - |
| 1528 | | - |
| 1529 | bool QColorDialogPrivate::selectColor(const QColor &col) | - |
| 1530 | { | - |
| 1531 | QRgb color = col.rgb(); | - |
| 1532 | | - |
| 1533 | if (standard) { | - |
| 1534 | const QRgb *standardColors = QColorDialogOptions::standardColors(); | - |
| 1535 | const QRgb *standardColorsEnd = standardColors + standardColorRows * colorColumns; | - |
| 1536 | const QRgb *match = std::find(standardColors, standardColorsEnd, color); | - |
| 1537 | if (match != standardColorsEnd) { | - |
| 1538 | const int index = int(match - standardColors); | - |
| 1539 | const int column = index / standardColorRows; | - |
| 1540 | const int row = index % standardColorRows; | - |
| 1541 | _q_newStandard(row, column); | - |
| 1542 | standard->setCurrent(row, column); | - |
| 1543 | standard->setSelected(row, column); | - |
| 1544 | standard->setFocus(); | - |
| 1545 | return true; | - |
| 1546 | } | - |
| 1547 | } | - |
| 1548 | | - |
| 1549 | if (custom) { | - |
| 1550 | const QRgb *customColors = QColorDialogOptions::customColors(); | - |
| 1551 | const QRgb *customColorsEnd = customColors + customColorRows * colorColumns; | - |
| 1552 | const QRgb *match = std::find(customColors, customColorsEnd, color); | - |
| 1553 | if (match != customColorsEnd) { | - |
| 1554 | const int index = int(match - customColors); | - |
| 1555 | const int column = index / customColorRows; | - |
| 1556 | const int row = index % customColorRows; | - |
| 1557 | _q_newCustom(row, column); | - |
| 1558 | custom->setCurrent(row, column); | - |
| 1559 | custom->setSelected(row, column); | - |
| 1560 | custom->setFocus(); | - |
| 1561 | return true; | - |
| 1562 | } | - |
| 1563 | } | - |
| 1564 | return false; | - |
| 1565 | } | - |
| 1566 | | - |
| 1567 | QColor QColorDialogPrivate::grabScreenColor(const QPoint &p) | - |
| 1568 | { | - |
| 1569 | const QDesktopWidget *desktop = QApplication::desktop(); | - |
| 1570 | const QPixmap pixmap = QGuiApplication::screens().at(desktop->screenNumber())->grabWindow(desktop->winId(), | - |
| 1571 | p.x(), p.y(), 1, 1); | - |
| 1572 | QImage i = pixmap.toImage(); | - |
| 1573 | return i.pixel(0, 0); | - |
| 1574 | } | - |
| 1575 | | - |
| 1576 | | - |
| 1577 | void QColorDialogPrivate::_q_newColorTypedIn(QRgb rgb) | - |
| 1578 | { | - |
| 1579 | if (!nativeDialogInUse) { | - |
| 1580 | int h, s, v; | - |
| 1581 | rgb2hsv(rgb, h, s, v); | - |
| 1582 | cp->setCol(h, s); | - |
| 1583 | lp->setCol(h, s, v); | - |
| 1584 | } | - |
| 1585 | } | - |
| 1586 | | - |
| 1587 | void QColorDialogPrivate::_q_nextCustom(int r, int c) | - |
| 1588 | { | - |
| 1589 | nextCust = r + customColorRows * c; | - |
| 1590 | } | - |
| 1591 | | - |
| 1592 | void QColorDialogPrivate::_q_newCustom(int r, int c) | - |
| 1593 | { | - |
| 1594 | const int i = r + customColorRows * c; | - |
| 1595 | setCurrentRgbColor(QColorDialogOptions::customColor(i)); | - |
| 1596 | if (standard) | - |
| 1597 | standard->setSelected(-1,-1); | - |
| 1598 | } | - |
| 1599 | | - |
| 1600 | void QColorDialogPrivate::_q_newStandard(int r, int c) | - |
| 1601 | { | - |
| 1602 | setCurrentRgbColor(QColorDialogOptions::standardColor(r + c * 6)); | - |
| 1603 | if (custom) | - |
| 1604 | custom->setSelected(-1,-1); | - |
| 1605 | } | - |
| 1606 | | - |
| 1607 | void QColorDialogPrivate::_q_pickScreenColor() | - |
| 1608 | { | - |
| 1609 | Q_Q(QColorDialog); | - |
| 1610 | if (!colorPickingEventFilter) | - |
| 1611 | colorPickingEventFilter = new QColorPickingEventFilter(this); | - |
| 1612 | q->installEventFilter(colorPickingEventFilter); | - |
| 1613 | | - |
| 1614 | beforeScreenColorPicking = cs->currentColor(); | - |
| 1615 | #ifndef QT_NO_CURSOR | - |
| 1616 | q->grabMouse(Qt::CrossCursor); | - |
| 1617 | #else | - |
| 1618 | q->grabMouse(); | - |
| 1619 | #endif | - |
| 1620 | | - |
| 1621 | #ifdef Q_OS_WIN32 // excludes WinCE and WinRT | - |
| 1622 | | - |
| 1623 | updateTimer->start(30); | - |
| 1624 | | - |
| 1625 | | - |
| 1626 | | - |
| 1627 | | - |
| 1628 | dummyTransparentWindow.show(); | - |
| 1629 | #endif | - |
| 1630 | q->grabKeyboard(); | - |
| 1631 | | - |
| 1632 | | - |
| 1633 | | - |
| 1634 | q->setMouseTracking(true); | - |
| 1635 | | - |
| 1636 | addCusBt->setDisabled(true); | - |
| 1637 | buttons->setDisabled(true); | - |
| 1638 | screenColorPickerButton->setDisabled(true); | - |
| 1639 | | - |
| 1640 | const QPoint globalPos = QCursor::pos(); | - |
| 1641 | q->setCurrentColor(grabScreenColor(globalPos)); | - |
| 1642 | updateColorLabelText(globalPos); | - |
| 1643 | } | - |
| 1644 | | - |
| 1645 | void QColorDialogPrivate::updateColorLabelText(const QPoint &globalPos) | - |
| 1646 | { | - |
| 1647 | lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2\nPress ESC to cancel") | - |
| 1648 | .arg(globalPos.x()) | - |
| 1649 | .arg(globalPos.y())); | - |
| 1650 | } | - |
| 1651 | | - |
| 1652 | void QColorDialogPrivate::releaseColorPicking() | - |
| 1653 | { | - |
| 1654 | Q_Q(QColorDialog); | - |
| 1655 | cp->setCrossVisible(true); | - |
| 1656 | q->removeEventFilter(colorPickingEventFilter); | - |
| 1657 | q->releaseMouse(); | - |
| 1658 | #ifdef Q_OS_WIN32 | - |
| 1659 | updateTimer->stop(); | - |
| 1660 | dummyTransparentWindow.setVisible(false); | - |
| 1661 | #endif | - |
| 1662 | q->releaseKeyboard(); | - |
| 1663 | q->setMouseTracking(false); | - |
| 1664 | lblScreenColorInfo->setText(QLatin1String("\n")); | - |
| 1665 | addCusBt->setDisabled(false); | - |
| 1666 | buttons->setDisabled(false); | - |
| 1667 | screenColorPickerButton->setDisabled(false); | - |
| 1668 | } | - |
| 1669 | | - |
| 1670 | void QColorDialogPrivate::init(const QColor &initial) | - |
| 1671 | { | - |
| 1672 | Q_Q(QColorDialog); | - |
| 1673 | | - |
| 1674 | q->setSizeGripEnabled(false); | - |
| 1675 | q->setWindowTitle(QColorDialog::tr("Select Color")); | - |
| 1676 | | - |
| 1677 | | - |
| 1678 | nativeDialogInUse = (platformColorDialogHelper() != 0); | - |
| 1679 | colorPickingEventFilter = 0; | - |
| 1680 | nextCust = 0; | - |
| 1681 | | - |
| 1682 | if (!nativeDialogInUse) | - |
| 1683 | initWidgets(); | - |
| 1684 | | - |
| 1685 | #ifdef Q_OS_WIN32 | - |
| 1686 | dummyTransparentWindow.resize(1, 1); | - |
| 1687 | dummyTransparentWindow.setFlags(Qt::Tool | Qt::FramelessWindowHint); | - |
| 1688 | #endif | - |
| 1689 | | - |
| 1690 | q->setCurrentColor(initial); | - |
| 1691 | } | - |
| 1692 | | - |
| 1693 | void QColorDialogPrivate::initWidgets() | - |
| 1694 | { | - |
| 1695 | Q_Q(QColorDialog); | - |
| 1696 | QVBoxLayout *mainLay = new QVBoxLayout(q); | - |
| 1697 | | - |
| 1698 | mainLay->setSizeConstraint(QLayout::SetFixedSize); | - |
| 1699 | | - |
| 1700 | QHBoxLayout *topLay = new QHBoxLayout(); | - |
| 1701 | mainLay->addLayout(topLay); | - |
| 1702 | | - |
| 1703 | leftLay = 0; | - |
| 1704 | | - |
| 1705 | #if defined(Q_OS_WINCE) || defined(QT_SMALL_COLORDIALOG) | - |
| 1706 | smallDisplay = true; | - |
| 1707 | const int lumSpace = 20; | - |
| 1708 | #else | - |
| 1709 | | - |
| 1710 | | - |
| 1711 | smallDisplay = (QApplication::desktop()->width() < 480 || QApplication::desktop()->height() < 350); | - |
| 1712 | const int lumSpace = topLay->spacing() / 2; | - |
| 1713 | #endif | - |
| 1714 | | - |
| 1715 | if (!smallDisplay) { | - |
| 1716 | leftLay = new QVBoxLayout; | - |
| 1717 | topLay->addLayout(leftLay); | - |
| 1718 | | - |
| 1719 | standard = new QColorWell(q, standardColorRows, colorColumns, QColorDialogOptions::standardColors()); | - |
| 1720 | lblBasicColors = new QLabel(q); | - |
| 1721 | #ifndef QT_NO_SHORTCUT | - |
| 1722 | lblBasicColors->setBuddy(standard); | - |
| 1723 | #endif | - |
| 1724 | q->connect(standard, SIGNAL(selected(int,int)), SLOT(_q_newStandard(int,int))); | - |
| 1725 | leftLay->addWidget(lblBasicColors); | - |
| 1726 | leftLay->addWidget(standard); | - |
| 1727 | | - |
| 1728 | #if !defined(Q_OS_WINCE) && !defined(QT_SMALL_COLORDIALOG) | - |
| 1729 | | - |
| 1730 | screenColorPickerButton = new QPushButton(); | - |
| 1731 | leftLay->addWidget(screenColorPickerButton); | - |
| 1732 | lblScreenColorInfo = new QLabel(QLatin1String("\n")); | - |
| 1733 | leftLay->addWidget(lblScreenColorInfo); | - |
| 1734 | q->connect(screenColorPickerButton, SIGNAL(clicked()), SLOT(_q_pickScreenColor())); | - |
| 1735 | #endif | - |
| 1736 | | - |
| 1737 | #if !defined(Q_OS_WINCE) | - |
| 1738 | leftLay->addStretch(); | - |
| 1739 | #endif | - |
| 1740 | | - |
| 1741 | custom = new QColorWell(q, customColorRows, colorColumns, QColorDialogOptions::customColors()); | - |
| 1742 | custom->setAcceptDrops(true); | - |
| 1743 | | - |
| 1744 | q->connect(custom, SIGNAL(selected(int,int)), SLOT(_q_newCustom(int,int))); | - |
| 1745 | q->connect(custom, SIGNAL(currentChanged(int,int)), SLOT(_q_nextCustom(int,int))); | - |
| 1746 | lblCustomColors = new QLabel(q); | - |
| 1747 | #ifndef QT_NO_SHORTCUT | - |
| 1748 | lblCustomColors->setBuddy(custom); | - |
| 1749 | #endif | - |
| 1750 | leftLay->addWidget(lblCustomColors); | - |
| 1751 | leftLay->addWidget(custom); | - |
| 1752 | | - |
| 1753 | addCusBt = new QPushButton(q); | - |
| 1754 | QObject::connect(addCusBt, SIGNAL(clicked()), q, SLOT(_q_addCustom())); | - |
| 1755 | leftLay->addWidget(addCusBt); | - |
| 1756 | } else { | - |
| 1757 | | - |
| 1758 | #if defined(QT_SMALL_COLORDIALOG) | - |
| 1759 | QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size(); | - |
| 1760 | pWidth = pHeight = qMin(screenSize.width(), screenSize.height()); | - |
| 1761 | pHeight -= 20; | - |
| 1762 | if(screenSize.height() > screenSize.width()) | - |
| 1763 | pWidth -= 20; | - |
| 1764 | #else | - |
| 1765 | pWidth = 150; | - |
| 1766 | pHeight = 100; | - |
| 1767 | #endif | - |
| 1768 | custom = 0; | - |
| 1769 | standard = 0; | - |
| 1770 | } | - |
| 1771 | | - |
| 1772 | QVBoxLayout *rightLay = new QVBoxLayout; | - |
| 1773 | topLay->addLayout(rightLay); | - |
| 1774 | | - |
| 1775 | QHBoxLayout *pickLay = new QHBoxLayout; | - |
| 1776 | rightLay->addLayout(pickLay); | - |
| 1777 | | - |
| 1778 | QVBoxLayout *cLay = new QVBoxLayout; | - |
| 1779 | pickLay->addLayout(cLay); | - |
| 1780 | cp = new QColorPicker(q); | - |
| 1781 | | - |
| 1782 | cp->setFrameStyle(QFrame::Panel + QFrame::Sunken); | - |
| 1783 | | - |
| 1784 | #if defined(QT_SMALL_COLORDIALOG) | - |
| 1785 | cp->hide(); | - |
| 1786 | #else | - |
| 1787 | cLay->addSpacing(lumSpace); | - |
| 1788 | cLay->addWidget(cp); | - |
| 1789 | #endif | - |
| 1790 | cLay->addSpacing(lumSpace); | - |
| 1791 | | - |
| 1792 | lp = new QColorLuminancePicker(q); | - |
| 1793 | #if defined(QT_SMALL_COLORDIALOG) | - |
| 1794 | lp->hide(); | - |
| 1795 | #else | - |
| 1796 | lp->setFixedWidth(20); | - |
| 1797 | pickLay->addSpacing(10); | - |
| 1798 | pickLay->addWidget(lp); | - |
| 1799 | pickLay->addStretch(); | - |
| 1800 | #endif | - |
| 1801 | | - |
| 1802 | QObject::connect(cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int))); | - |
| 1803 | QObject::connect(lp, SIGNAL(newHsv(int,int,int)), q, SLOT(_q_newHsv(int,int,int))); | - |
| 1804 | | - |
| 1805 | rightLay->addStretch(); | - |
| 1806 | | - |
| 1807 | cs = new QColorShower(q); | - |
| 1808 | pickLay->setMargin(cs->gl->margin()); | - |
| 1809 | QObject::connect(cs, SIGNAL(newCol(QRgb)), q, SLOT(_q_newColorTypedIn(QRgb))); | - |
| 1810 | QObject::connect(cs, SIGNAL(currentColorChanged(QColor)), | - |
| 1811 | q, SIGNAL(currentColorChanged(QColor))); | - |
| 1812 | #if defined(QT_SMALL_COLORDIALOG) | - |
| 1813 | topLay->addWidget(cs); | - |
| 1814 | #else | - |
| 1815 | rightLay->addWidget(cs); | - |
| 1816 | if (leftLay) | - |
| 1817 | leftLay->addSpacing(cs->gl->margin()); | - |
| 1818 | #endif | - |
| 1819 | | - |
| 1820 | buttons = new QDialogButtonBox(q); | - |
| 1821 | mainLay->addWidget(buttons); | - |
| 1822 | | - |
| 1823 | ok = buttons->addButton(QDialogButtonBox::Ok); | - |
| 1824 | QObject::connect(ok, SIGNAL(clicked()), q, SLOT(accept())); | - |
| 1825 | ok->setDefault(true); | - |
| 1826 | cancel = buttons->addButton(QDialogButtonBox::Cancel); | - |
| 1827 | QObject::connect(cancel, SIGNAL(clicked()), q, SLOT(reject())); | - |
| 1828 | | - |
| 1829 | #ifdef Q_OS_WIN32 | - |
| 1830 | updateTimer = new QTimer(q); | - |
| 1831 | QObject::connect(updateTimer, SIGNAL(timeout()), q, SLOT(_q_updateColorPicking())); | - |
| 1832 | #endif | - |
| 1833 | retranslateStrings(); | - |
| 1834 | } | - |
| 1835 | | - |
| 1836 | void QColorDialogPrivate::initHelper(QPlatformDialogHelper *h) | - |
| 1837 | { | - |
| 1838 | QColorDialog *d = q_func(); | - |
| 1839 | QObject::connect(h, SIGNAL(currentColorChanged(QColor)), d, SIGNAL(currentColorChanged(QColor))); | - |
| 1840 | QObject::connect(h, SIGNAL(colorSelected(QColor)), d, SIGNAL(colorSelected(QColor))); | - |
| 1841 | static_cast<QPlatformColorDialogHelper *>(h)->setOptions(options); | - |
| 1842 | } | - |
| 1843 | | - |
| 1844 | void QColorDialogPrivate::helperPrepareShow(QPlatformDialogHelper *) | - |
| 1845 | { | - |
| 1846 | options->setWindowTitle(q_func()->windowTitle()); | - |
| 1847 | } | - |
| 1848 | | - |
| 1849 | void QColorDialogPrivate::_q_addCustom() | - |
| 1850 | { | - |
| 1851 | QColorDialogOptions::setCustomColor(nextCust, cs->currentColor()); | - |
| 1852 | if (custom) | - |
| 1853 | custom->update(); | - |
| 1854 | nextCust = (nextCust+1) % 16; | - |
| 1855 | } | - |
| 1856 | | - |
| 1857 | void QColorDialogPrivate::retranslateStrings() | - |
| 1858 | { | - |
| 1859 | if (!smallDisplay) { | - |
| 1860 | lblBasicColors->setText(QColorDialog::tr("&Basic colors")); | - |
| 1861 | lblCustomColors->setText(QColorDialog::tr("&Custom colors")); | - |
| 1862 | addCusBt->setText(QColorDialog::tr("&Add to Custom Colors")); | - |
| 1863 | screenColorPickerButton->setText(QColorDialog::tr("&Pick Screen Color")); | - |
| 1864 | } | - |
| 1865 | | - |
| 1866 | cs->retranslateStrings(); | - |
| 1867 | } | - |
| 1868 | | - |
| 1869 | bool QColorDialogPrivate::canBeNativeDialog() const | - |
| 1870 | { | - |
| 1871 | | - |
| 1872 | | - |
| 1873 | const QDialog * const q = static_cast<const QDialog*>(q_ptr); | - |
| 1874 | if (nativeDialogInUse)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1875 | return true; never executed: return true; | 0 |
| 1876 | if (QCoreApplication::testAttribute(Qt::AA_DontUseNativeDialogs)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1877 | ||| TRUE | never evaluated | | FALSE | never evaluated |
q->testAttribute(Qt::WA_DontShowOnScreen))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| return false;| TRUE | never evaluated | | FALSE | never evaluated |
| |
| if| TRUE | never evaluated | | FALSE | never evaluated |
)| TRUE | never evaluated | | FALSE | never evaluated |
| |
| 1878 | ||| TRUE | never evaluated | | FALSE | never evaluated |
(options->options() & QColorDialog::DontUseNativeDialog))) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1879 | return false; never executed: return false; | 0 |
| 1880 | } | - |
| 1881 | | - |
| 1882 | QLatin1String staticName(QColorDialog::staticMetaObject.className()); | - |
| 1883 | QLatin1String dynamicName(q->metaObject()->className()); | - |
| 1884 | return (staticName == dynamicName); never executed: return (staticName == dynamicName); | 0 |
| 1885 | } | - |
| 1886 | | - |
| 1887 | static const Qt::WindowFlags DefaultWindowFlags = | - |
| 1888 | Qt::Dialog | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint | - |
| 1889 | | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; | - |
| 1890 | | - |
| 1891 | | - |
| 1892 | | - |
| 1893 | | - |
| 1894 | | - |
| 1895 | | - |
| 1896 | | - |
| 1897 | | - |
| 1898 | | - |
| 1899 | | - |
| 1900 | | - |
| 1901 | | - |
| 1902 | | - |
| 1903 | | - |
| 1904 | | - |
| 1905 | | - |
| 1906 | | - |
| 1907 | | - |
| 1908 | | - |
| 1909 | | - |
| 1910 | | - |
| 1911 | | - |
| 1912 | | - |
| 1913 | | - |
| 1914 | | - |
| 1915 | | - |
| 1916 | | - |
| 1917 | | - |
| 1918 | | - |
| 1919 | | - |
| 1920 | | - |
| 1921 | | - |
| 1922 | | - |
| 1923 | | - |
| 1924 | | - |
| 1925 | | - |
| 1926 | | - |
| 1927 | | - |
| 1928 | | - |
| 1929 | | - |
| 1930 | | - |
| 1931 | | - |
| 1932 | | - |
| 1933 | | - |
| 1934 | | - |
| 1935 | QColorDialog::QColorDialog(QWidget *parent) | - |
| 1936 | : QDialog(*new QColorDialogPrivate, parent, DefaultWindowFlags) | - |
| 1937 | { | - |
| 1938 | Q_D(QColorDialog); | - |
| 1939 | d->init(Qt::white); | - |
| 1940 | } | - |
| 1941 | | - |
| 1942 | | - |
| 1943 | | - |
| 1944 | | - |
| 1945 | | - |
| 1946 | | - |
| 1947 | | - |
| 1948 | QColorDialog::QColorDialog(const QColor &initial, QWidget *parent) | - |
| 1949 | : QDialog(*new QColorDialogPrivate, parent, DefaultWindowFlags) | - |
| 1950 | { | - |
| 1951 | Q_D(QColorDialog); | - |
| 1952 | d->init(initial); | - |
| 1953 | } | - |
| 1954 | | - |
| 1955 | void QColorDialogPrivate::setCurrentColor(const QColor &color, SetColorMode setColorMode) | - |
| 1956 | { | - |
| 1957 | if (nativeDialogInUse) { | - |
| 1958 | platformColorDialogHelper()->setCurrentColor(color); | - |
| 1959 | return; | - |
| 1960 | } | - |
| 1961 | | - |
| 1962 | if (setColorMode & ShowColor) { | - |
| 1963 | setCurrentRgbColor(color.rgb()); | - |
| 1964 | setCurrentAlpha(color.alpha()); | - |
| 1965 | } | - |
| 1966 | if (setColorMode & SelectColor) | - |
| 1967 | selectColor(color); | - |
| 1968 | } | - |
| 1969 | | - |
| 1970 | | - |
| 1971 | | - |
| 1972 | | - |
| 1973 | | - |
| 1974 | | - |
| 1975 | void QColorDialog::setCurrentColor(const QColor &color) | - |
| 1976 | { | - |
| 1977 | Q_D(QColorDialog); | - |
| 1978 | d->setCurrentColor(color); | - |
| 1979 | } | - |
| 1980 | | - |
| 1981 | QColor QColorDialog::currentColor() const | - |
| 1982 | { | - |
| 1983 | Q_D(const QColorDialog); | - |
| 1984 | return d->currentQColor(); | - |
| 1985 | } | - |
| 1986 | | - |
| 1987 | | - |
| 1988 | | - |
| 1989 | | - |
| 1990 | | - |
| 1991 | | - |
| 1992 | | - |
| 1993 | | - |
| 1994 | | - |
| 1995 | QColor QColorDialog::selectedColor() const | - |
| 1996 | { | - |
| 1997 | Q_D(const QColorDialog); | - |
| 1998 | return d->selectedQColor; | - |
| 1999 | } | - |
| 2000 | | - |
| 2001 | | - |
| 2002 | | - |
| 2003 | | - |
| 2004 | | - |
| 2005 | | - |
| 2006 | | - |
| 2007 | void QColorDialog::setOption(ColorDialogOption option, bool on) | - |
| 2008 | { | - |
| 2009 | const QColorDialog::ColorDialogOptions previousOptions = options(); | - |
| 2010 | if (!(previousOptions & option) != !on) | - |
| 2011 | setOptions(previousOptions ^ option); | - |
| 2012 | } | - |
| 2013 | | - |
| 2014 | | - |
| 2015 | | - |
| 2016 | | - |
| 2017 | | - |
| 2018 | | - |
| 2019 | | - |
| 2020 | | - |
| 2021 | | - |
| 2022 | bool QColorDialog::testOption(ColorDialogOption option) const | - |
| 2023 | { | - |
| 2024 | Q_D(const QColorDialog); | - |
| 2025 | return d->options->testOption(static_cast<QColorDialogOptions::ColorDialogOption>(option)); | - |
| 2026 | } | - |
| 2027 | | - |
| 2028 | | - |
| 2029 | | - |
| 2030 | | - |
| 2031 | | - |
| 2032 | | - |
| 2033 | | - |
| 2034 | | - |
| 2035 | | - |
| 2036 | | - |
| 2037 | | - |
| 2038 | | - |
| 2039 | | - |
| 2040 | void QColorDialog::setOptions(ColorDialogOptions options) | - |
| 2041 | { | - |
| 2042 | Q_D(QColorDialog); | - |
| 2043 | | - |
| 2044 | if (QColorDialog::options() == options) | - |
| 2045 | return; | - |
| 2046 | | - |
| 2047 | d->options->setOptions(QColorDialogOptions::ColorDialogOptions(int(options))); | - |
| 2048 | if ((options & DontUseNativeDialog) && d->nativeDialogInUse) { | - |
| 2049 | d->nativeDialogInUse = false; | - |
| 2050 | d->initWidgets(); | - |
| 2051 | } | - |
| 2052 | if (!d->nativeDialogInUse) { | - |
| 2053 | d->buttons->setVisible(!(options & NoButtons)); | - |
| 2054 | d->showAlpha(options & ShowAlphaChannel); | - |
| 2055 | } | - |
| 2056 | } | - |
| 2057 | | - |
| 2058 | QColorDialog::ColorDialogOptions QColorDialog::options() const | - |
| 2059 | { | - |
| 2060 | Q_D(const QColorDialog); | - |
| 2061 | return QColorDialog::ColorDialogOptions(int(d->options->options())); | - |
| 2062 | } | - |
| 2063 | | - |
| 2064 | | - |
| 2065 | | - |
| 2066 | | - |
| 2067 | | - |
| 2068 | | - |
| 2069 | | - |
| 2070 | | - |
| 2071 | | - |
| 2072 | | - |
| 2073 | | - |
| 2074 | | - |
| 2075 | | - |
| 2076 | | - |
| 2077 | | - |
| 2078 | | - |
| 2079 | | - |
| 2080 | | - |
| 2081 | | - |
| 2082 | | - |
| 2083 | | - |
| 2084 | | - |
| 2085 | | - |
| 2086 | | - |
| 2087 | | - |
| 2088 | | - |
| 2089 | | - |
| 2090 | | - |
| 2091 | | - |
| 2092 | | - |
| 2093 | | - |
| 2094 | | - |
| 2095 | | - |
| 2096 | | - |
| 2097 | | - |
| 2098 | | - |
| 2099 | | - |
| 2100 | | - |
| 2101 | | - |
| 2102 | void QColorDialog::setVisible(bool visible) | - |
| 2103 | { | - |
| 2104 | Q_D(QColorDialog); | - |
| 2105 | | - |
| 2106 | if (visible){ | - |
| 2107 | if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) | - |
| 2108 | return; | - |
| 2109 | } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) | - |
| 2110 | return; | - |
| 2111 | | - |
| 2112 | if (visible) | - |
| 2113 | d->selectedQColor = QColor(); | - |
| 2114 | | - |
| 2115 | if (d->nativeDialogInUse) { | - |
| 2116 | d->setNativeDialogVisible(visible); | - |
| 2117 | | - |
| 2118 | | - |
| 2119 | setAttribute(Qt::WA_DontShowOnScreen); | - |
| 2120 | } else { | - |
| 2121 | setAttribute(Qt::WA_DontShowOnScreen, false); | - |
| 2122 | } | - |
| 2123 | | - |
| 2124 | QDialog::setVisible(visible); | - |
| 2125 | } | - |
| 2126 | | - |
| 2127 | | - |
| 2128 | | - |
| 2129 | | - |
| 2130 | | - |
| 2131 | | - |
| 2132 | | - |
| 2133 | | - |
| 2134 | | - |
| 2135 | | - |
| 2136 | void QColorDialog::open(QObject *receiver, const char *member) | - |
| 2137 | { | - |
| 2138 | Q_D(QColorDialog); | - |
| 2139 | connect(this, SIGNAL(colorSelected(QColor)), receiver, member); | - |
| 2140 | d->receiverToDisconnectOnClose = receiver; | - |
| 2141 | d->memberToDisconnectOnClose = member; | - |
| 2142 | QDialog::open(); | - |
| 2143 | } | - |
| 2144 | | - |
| 2145 | | - |
| 2146 | | - |
| 2147 | | - |
| 2148 | | - |
| 2149 | | - |
| 2150 | | - |
| 2151 | | - |
| 2152 | | - |
| 2153 | | - |
| 2154 | | - |
| 2155 | QColor QColorDialog::getColor(const QColor &initial, QWidget *parent, const QString &title, | - |
| 2156 | ColorDialogOptions options) | - |
| 2157 | { | - |
| 2158 | QColorDialog dlg(parent); | - |
| 2159 | if (!title.isEmpty()) | - |
| 2160 | dlg.setWindowTitle(title); | - |
| 2161 | dlg.setOptions(options); | - |
| 2162 | dlg.setCurrentColor(initial); | - |
| 2163 | dlg.exec(); | - |
| 2164 | return dlg.selectedColor(); | - |
| 2165 | } | - |
| 2166 | | - |
| 2167 | | - |
| 2168 | | - |
| 2169 | | - |
| 2170 | | - |
| 2171 | | - |
| 2172 | | - |
| 2173 | | - |
| 2174 | | - |
| 2175 | | - |
| 2176 | | - |
| 2177 | | - |
| 2178 | | - |
| 2179 | | - |
| 2180 | | - |
| 2181 | | - |
| 2182 | | - |
| 2183 | QRgb QColorDialog::getRgba(QRgb initial, bool *ok, QWidget *parent) | - |
| 2184 | { | - |
| 2185 | const QColor color = getColor(QColor::fromRgba(initial), parent, QString(), | - |
| 2186 | ShowAlphaChannel); | - |
| 2187 | QRgb result = color.isValid() ? color.rgba() : initial; | - |
| 2188 | if (ok) | - |
| 2189 | *ok = color.isValid(); | - |
| 2190 | return result; | - |
| 2191 | } | - |
| 2192 | | - |
| 2193 | | - |
| 2194 | | - |
| 2195 | | - |
| 2196 | | - |
| 2197 | QColorDialog::~QColorDialog() | - |
| 2198 | { | - |
| 2199 | | - |
| 2200 | } | - |
| 2201 | | - |
| 2202 | | - |
| 2203 | | - |
| 2204 | | - |
| 2205 | void QColorDialog::changeEvent(QEvent *e) | - |
| 2206 | { | - |
| 2207 | Q_D(QColorDialog); | - |
| 2208 | if (e->type() == QEvent::LanguageChange) | - |
| 2209 | d->retranslateStrings(); | - |
| 2210 | QDialog::changeEvent(e); | - |
| 2211 | } | - |
| 2212 | | - |
| 2213 | void QColorDialogPrivate::_q_updateColorPicking() | - |
| 2214 | { | - |
| 2215 | #ifndef QT_NO_CURSOR | - |
| 2216 | Q_Q(QColorDialog); | - |
| 2217 | static QPoint lastGlobalPos; | - |
| 2218 | QPoint newGlobalPos = QCursor::pos(); | - |
| 2219 | if (lastGlobalPos == newGlobalPos) | - |
| 2220 | return; | - |
| 2221 | lastGlobalPos = newGlobalPos; | - |
| 2222 | | - |
| 2223 | if (!q->rect().contains(q->mapFromGlobal(newGlobalPos))) { | - |
| 2224 | updateColorPicking(newGlobalPos); | - |
| 2225 | #ifdef Q_OS_WIN32 | - |
| 2226 | dummyTransparentWindow.setPosition(newGlobalPos); | - |
| 2227 | #endif | - |
| 2228 | } | - |
| 2229 | #endif // ! QT_NO_CURSOR | - |
| 2230 | } | - |
| 2231 | | - |
| 2232 | void QColorDialogPrivate::updateColorPicking(const QPoint &globalPos) | - |
| 2233 | { | - |
| 2234 | const QColor color = grabScreenColor(globalPos); | - |
| 2235 | | - |
| 2236 | | - |
| 2237 | setCurrentColor(color, ShowColor); | - |
| 2238 | updateColorLabelText(globalPos); | - |
| 2239 | | - |
| 2240 | } | - |
| 2241 | | - |
| 2242 | bool QColorDialogPrivate::handleColorPickingMouseMove(QMouseEvent *e) | - |
| 2243 | { | - |
| 2244 | | - |
| 2245 | cp->setCrossVisible(!cp->geometry().contains(e->pos())); | - |
| 2246 | | - |
| 2247 | updateColorPicking(e->globalPos()); | - |
| 2248 | return true; | - |
| 2249 | } | - |
| 2250 | | - |
| 2251 | bool QColorDialogPrivate::handleColorPickingMouseButtonRelease(QMouseEvent *e) | - |
| 2252 | { | - |
| 2253 | setCurrentColor(grabScreenColor(e->globalPos()), SetColorAll); | - |
| 2254 | releaseColorPicking(); | - |
| 2255 | return true; | - |
| 2256 | } | - |
| 2257 | | - |
| 2258 | bool QColorDialogPrivate::handleColorPickingKeyPress(QKeyEvent *e) | - |
| 2259 | { | - |
| 2260 | Q_Q(QColorDialog); | - |
| 2261 | if (e->matches(QKeySequence::Cancel)) { | - |
| 2262 | releaseColorPicking(); | - |
| 2263 | q->setCurrentColor(beforeScreenColorPicking); | - |
| 2264 | } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { | - |
| 2265 | q->setCurrentColor(grabScreenColor(QCursor::pos())); | - |
| 2266 | releaseColorPicking(); | - |
| 2267 | } | - |
| 2268 | e->accept(); | - |
| 2269 | return true; | - |
| 2270 | } | - |
| 2271 | | - |
| 2272 | | - |
| 2273 | | - |
| 2274 | | - |
| 2275 | | - |
| 2276 | | - |
| 2277 | | - |
| 2278 | | - |
| 2279 | void QColorDialog::done(int result) | - |
| 2280 | { | - |
| 2281 | Q_D(QColorDialog); | - |
| 2282 | if (result == Accepted) { | - |
| 2283 | d->selectedQColor = d->currentQColor(); | - |
| 2284 | emit colorSelected(d->selectedQColor); | - |
| 2285 | } else { | - |
| 2286 | d->selectedQColor = QColor(); | - |
| 2287 | } | - |
| 2288 | QDialog::done(result); | - |
| 2289 | if (d->receiverToDisconnectOnClose) { | - |
| 2290 | disconnect(this, SIGNAL(colorSelected(QColor)), | - |
| 2291 | d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); | - |
| 2292 | d->receiverToDisconnectOnClose = 0; | - |
| 2293 | } | - |
| 2294 | d->memberToDisconnectOnClose.clear(); | - |
| 2295 | } | - |
| 2296 | | - |
| 2297 | QT_END_NAMESPACE | - |
| 2298 | | - |
| 2299 | #include "qcolordialog.moc" | - |
| 2300 | #include "moc_qcolordialog.cpp" | - |
| 2301 | | - |
| 2302 | #endif // QT_NO_COLORDIALOG | - |
| 2303 | | - |
| | |