author | Wuzzy <Wuzzy2@mail.ru> |
Thu, 18 Jul 2019 00:45:39 +0200 | |
changeset 15270 | 441bdf1e6026 |
parent 15182 | d20e52a646e7 |
permissions | -rw-r--r-- |
7130 | 1 |
#include <QStandardItemModel> |
2 |
#include <QMouseEvent> |
|
3 |
#include <QWheelEvent> |
|
7749
edad8a7bcaea
Convert ColorWidget from QWidget to QFrame and make use of The Box Model(tm) in stylesheet
unc0rr
parents:
7130
diff
changeset
|
4 |
#include <QColor> |
7130 | 5 |
|
6 |
#include "colorwidget.h" |
|
7 |
#include "hwconsts.h" |
|
8 |
||
9 |
ColorWidget::ColorWidget(QStandardItemModel *colorsModel, QWidget *parent) : |
|
7749
edad8a7bcaea
Convert ColorWidget from QWidget to QFrame and make use of The Box Model(tm) in stylesheet
unc0rr
parents:
7130
diff
changeset
|
10 |
QFrame(parent) |
7130 | 11 |
{ |
12 |
m_colorsModel = colorsModel; |
|
13 |
||
14 |
setColor(0); |
|
15 |
setAutoFillBackground(true); |
|
16 |
||
17 |
connect(m_colorsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex))); |
|
18 |
} |
|
19 |
||
20 |
ColorWidget::~ColorWidget() |
|
21 |
{ |
|
22 |
||
23 |
} |
|
24 |
||
25 |
void ColorWidget::setColor(int color) |
|
26 |
{ |
|
27 |
Q_ASSERT_X(color >= 0 && color < m_colorsModel->rowCount(), "ColorWidget::setColor", "Color index out of range"); |
|
28 |
||
29 |
m_color = color; |
|
30 |
||
31 |
QStandardItem * item = m_colorsModel->item(m_color); |
|
32 |
||
15021
d597a851f5d8
Frontend: Highlight button when pressed
Wuzzy <Wuzzy2@mail.ru>
parents:
13228
diff
changeset
|
33 |
setStyleSheet(QString("* { border: 2px solid #ffcc00; border-radius: 8px; background: %1 } :disabled { border-color: #a0a0a0; } :hover { border-color: #ffff00; }").arg(item->data().value<QColor>().name())); |
7749
edad8a7bcaea
Convert ColorWidget from QWidget to QFrame and make use of The Box Model(tm) in stylesheet
unc0rr
parents:
7130
diff
changeset
|
34 |
/* |
7130 | 35 |
QPalette p = palette(); |
36 |
p.setColor(QPalette::Window, item->data().value<QColor>()); |
|
37 |
setPalette(p); |
|
7749
edad8a7bcaea
Convert ColorWidget from QWidget to QFrame and make use of The Box Model(tm) in stylesheet
unc0rr
parents:
7130
diff
changeset
|
38 |
*/ |
7130 | 39 |
|
40 |
emit colorChanged(m_color); |
|
41 |
} |
|
42 |
||
43 |
int ColorWidget::getColor() |
|
44 |
{ |
|
45 |
return m_color; |
|
46 |
} |
|
47 |
||
48 |
void ColorWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) |
|
49 |
{ |
|
50 |
if(m_color >= topLeft.row() && m_color <= bottomRight.row()) |
|
51 |
setColor(m_color); |
|
52 |
} |
|
53 |
||
54 |
void ColorWidget::mousePressEvent(QMouseEvent * event) |
|
55 |
{ |
|
56 |
switch(event->button()) |
|
57 |
{ |
|
58 |
case Qt::LeftButton: |
|
7750
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
59 |
nextColor(); |
7130 | 60 |
break; |
61 |
case Qt::RightButton: |
|
7750
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
62 |
previousColor(); |
7130 | 63 |
break; |
64 |
default:; |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
void ColorWidget::wheelEvent(QWheelEvent *event) |
|
69 |
{ |
|
15182
d20e52a646e7
Fix mouse wheel scrolling team list when used on team color widget
Wuzzy <Wuzzy2@mail.ru>
parents:
15021
diff
changeset
|
70 |
event->accept(); |
7130 | 71 |
if(event->delta() > 0) |
7750
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
72 |
previousColor(); |
7130 | 73 |
else |
7750
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
74 |
nextColor(); |
7130 | 75 |
} |
7750
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
76 |
|
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
77 |
void ColorWidget::nextColor() |
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
78 |
{ |
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
79 |
setColor((m_color + 1) % m_colorsModel->rowCount()); |
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
80 |
} |
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
81 |
|
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
82 |
void ColorWidget::previousColor() |
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
83 |
{ |
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
84 |
setColor((m_color + m_colorsModel->rowCount() - 1) % m_colorsModel->rowCount()); |
31e4f6c1834b
small tweak. (reverse mouse wheel directions for color change)
sheepluva
parents:
7749
diff
changeset
|
85 |
} |