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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtpropertybrowserutils_p.h"
#include <QtWidgets/QApplication>
#include <QtGui/QPainter>
#include <QtWidgets/QHBoxLayout>
#include <QtGui/QMouseEvent>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QMenu>
#include <QtCore/QLocale>
QT_BEGIN_NAMESPACE
QtCursorDatabase::QtCursorDatabase()
{
appendCursor(Qt::ArrowCursor, QCoreApplication::translate("QtCursorDatabase", "Arrow"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-arrow.png")));
appendCursor(Qt::UpArrowCursor, QCoreApplication::translate("QtCursorDatabase", "Up Arrow"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-uparrow.png")));
appendCursor(Qt::CrossCursor, QCoreApplication::translate("QtCursorDatabase", "Cross"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-cross.png")));
appendCursor(Qt::WaitCursor, QCoreApplication::translate("QtCursorDatabase", "Wait"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-wait.png")));
appendCursor(Qt::IBeamCursor, QCoreApplication::translate("QtCursorDatabase", "IBeam"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-ibeam.png")));
appendCursor(Qt::SizeVerCursor, QCoreApplication::translate("QtCursorDatabase", "Size Vertical"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-sizev.png")));
appendCursor(Qt::SizeHorCursor, QCoreApplication::translate("QtCursorDatabase", "Size Horizontal"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-sizeh.png")));
appendCursor(Qt::SizeFDiagCursor, QCoreApplication::translate("QtCursorDatabase", "Size Backslash"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-sizef.png")));
appendCursor(Qt::SizeBDiagCursor, QCoreApplication::translate("QtCursorDatabase", "Size Slash"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-sizeb.png")));
appendCursor(Qt::SizeAllCursor, QCoreApplication::translate("QtCursorDatabase", "Size All"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-sizeall.png")));
appendCursor(Qt::BlankCursor, QCoreApplication::translate("QtCursorDatabase", "Blank"),
QIcon());
appendCursor(Qt::SplitVCursor, QCoreApplication::translate("QtCursorDatabase", "Split Vertical"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-vsplit.png")));
appendCursor(Qt::SplitHCursor, QCoreApplication::translate("QtCursorDatabase", "Split Horizontal"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-hsplit.png")));
appendCursor(Qt::PointingHandCursor, QCoreApplication::translate("QtCursorDatabase", "Pointing Hand"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-hand.png")));
appendCursor(Qt::ForbiddenCursor, QCoreApplication::translate("QtCursorDatabase", "Forbidden"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-forbidden.png")));
appendCursor(Qt::OpenHandCursor, QCoreApplication::translate("QtCursorDatabase", "Open Hand"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-openhand.png")));
appendCursor(Qt::ClosedHandCursor, QCoreApplication::translate("QtCursorDatabase", "Closed Hand"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-closedhand.png")));
appendCursor(Qt::WhatsThisCursor, QCoreApplication::translate("QtCursorDatabase", "What's This"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-whatsthis.png")));
appendCursor(Qt::BusyCursor, QCoreApplication::translate("QtCursorDatabase", "Busy"),
QIcon(QLatin1String(":/qt-project.org/qtpropertybrowser/images/cursor-busy.png")));
}
void QtCursorDatabase::clear()
{
m_cursorNames.clear();
m_cursorIcons.clear();
m_valueToCursorShape.clear();
m_cursorShapeToValue.clear();
}
void QtCursorDatabase::appendCursor(Qt::CursorShape shape, const QString &name, const QIcon &icon)
{
if (m_cursorShapeToValue.contains(shape))
return;
const int value = m_cursorNames.count();
m_cursorNames.append(name);
m_cursorIcons.insert(value, icon);
m_valueToCursorShape.insert(value, shape);
m_cursorShapeToValue.insert(shape, value);
}
QStringList QtCursorDatabase::cursorShapeNames() const
{
return m_cursorNames;
}
QMap<int, QIcon> QtCursorDatabase::cursorShapeIcons() const
{
return m_cursorIcons;
}
QString QtCursorDatabase::cursorToShapeName(const QCursor &cursor) const
{
int val = cursorToValue(cursor);
if (val >= 0)
return m_cursorNames.at(val);
return QString();
}
QIcon QtCursorDatabase::cursorToShapeIcon(const QCursor &cursor) const
{
int val = cursorToValue(cursor);
return m_cursorIcons.value(val);
}
int QtCursorDatabase::cursorToValue(const QCursor &cursor) const
{
#ifndef QT_NO_CURSOR
Qt::CursorShape shape = cursor.shape();
if (m_cursorShapeToValue.contains(shape))
return m_cursorShapeToValue[shape];
#endif
return -1;
}
#ifndef QT_NO_CURSOR
QCursor QtCursorDatabase::valueToCursor(int value) const
{
if (m_valueToCursorShape.contains(value))
return QCursor(m_valueToCursorShape[value]);
return QCursor();
}
#endif
QPixmap QtPropertyBrowserUtils::brushValuePixmap(const QBrush &b)
{
QImage img(16, 16, QImage::Format_ARGB32_Premultiplied);
img.fill(0);
QPainter painter(&img);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(0, 0, img.width(), img.height(), b);
QColor color = b.color();
if (color.alpha() != 255) { // indicate alpha by an inset
QBrush opaqueBrush = b;
color.setAlpha(255);
opaqueBrush.setColor(color);
painter.fillRect(img.width() / 4, img.height() / 4,
img.width() / 2, img.height() / 2, opaqueBrush);
}
painter.end();
return QPixmap::fromImage(img);
}
QIcon QtPropertyBrowserUtils::brushValueIcon(const QBrush &b)
{
return QIcon(brushValuePixmap(b));
}
QString QtPropertyBrowserUtils::colorValueText(const QColor &c)
{
return QCoreApplication::translate("QtPropertyBrowserUtils", "[%1, %2, %3] (%4)")
.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
}
QPixmap QtPropertyBrowserUtils::fontValuePixmap(const QFont &font)
{
QFont f = font;
QImage img(16, 16, QImage::Format_ARGB32_Premultiplied);
img.fill(0);
QPainter p(&img);
p.setRenderHint(QPainter::TextAntialiasing, true);
p.setRenderHint(QPainter::Antialiasing, true);
f.setPointSize(13);
p.setFont(f);
QTextOption t;
t.setAlignment(Qt::AlignCenter);
p.drawText(QRect(0, 0, 16, 16), QString(QLatin1Char('A')), t);
return QPixmap::fromImage(img);
}
QIcon QtPropertyBrowserUtils::fontValueIcon(const QFont &f)
{
return QIcon(fontValuePixmap(f));
}
QString QtPropertyBrowserUtils::fontValueText(const QFont &f)
{
return QCoreApplication::translate("QtPropertyBrowserUtils", "[%1, %2]")
.arg(f.family()).arg(f.pointSize());
}
QString QtPropertyBrowserUtils::dateFormat()
{
QLocale loc;
return loc.dateFormat(QLocale::ShortFormat);
}
QString QtPropertyBrowserUtils::timeFormat()
{
QLocale loc;
// ShortFormat is missing seconds on UNIX.
return loc.timeFormat(QLocale::LongFormat);
}
QString QtPropertyBrowserUtils::dateTimeFormat()
{
QString format = dateFormat();
format += QLatin1Char(' ');
format += timeFormat();
return format;
}
QtBoolEdit::QtBoolEdit(QWidget *parent) :
QWidget(parent),
m_checkBox(new QCheckBox(this)),
m_textVisible(true)
{
QHBoxLayout *lt = new QHBoxLayout;
if (QApplication::layoutDirection() == Qt::LeftToRight)
lt->setContentsMargins(4, 0, 0, 0);
else
lt->setContentsMargins(0, 0, 4, 0);
lt->addWidget(m_checkBox);
setLayout(lt);
connect(m_checkBox, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
setFocusProxy(m_checkBox);
m_checkBox->setText(tr("True"));
}
void QtBoolEdit::setTextVisible(bool textVisible)
{
if (m_textVisible == textVisible)
return;
m_textVisible = textVisible;
if (m_textVisible)
m_checkBox->setText(isChecked() ? tr("True") : tr("False"));
else
m_checkBox->setText(QString());
}
Qt::CheckState QtBoolEdit::checkState() const
{
return m_checkBox->checkState();
}
void QtBoolEdit::setCheckState(Qt::CheckState state)
{
m_checkBox->setCheckState(state);
}
bool QtBoolEdit::isChecked() const
{
return m_checkBox->isChecked();
}
void QtBoolEdit::setChecked(bool c)
{
m_checkBox->setChecked(c);
if (!m_textVisible)
return;
m_checkBox->setText(isChecked() ? tr("True") : tr("False"));
}
bool QtBoolEdit::blockCheckBoxSignals(bool block)
{
return m_checkBox->blockSignals(block);
}
void QtBoolEdit::mousePressEvent(QMouseEvent *event)
{
if (event->buttons() == Qt::LeftButton) {
m_checkBox->click();
event->accept();
} else {
QWidget::mousePressEvent(event);
}
}
QT_END_NAMESPACE
|