43 #include <QApplication>
45 #include <QHBoxLayout>
46 #include <QMouseEvent>
50 #include <QStyleOption>
56 appendCursor(Qt::ArrowCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Arrow"),
57 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-arrow.png")));
58 appendCursor(Qt::UpArrowCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Up Arrow"),
59 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-uparrow.png")));
60 appendCursor(Qt::CrossCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Cross"),
61 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-cross.png")));
62 appendCursor(Qt::WaitCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Wait"),
63 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-wait.png")));
64 appendCursor(Qt::IBeamCursor, QCoreApplication::translate(
"QtCursorDatabase",
"IBeam"),
65 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-ibeam.png")));
66 appendCursor(Qt::SizeVerCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Size Vertical"),
67 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-sizev.png")));
68 appendCursor(Qt::SizeHorCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Size Horizontal"),
69 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-sizeh.png")));
70 appendCursor(Qt::SizeFDiagCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Size Backslash"),
71 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-sizef.png")));
72 appendCursor(Qt::SizeBDiagCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Size Slash"),
73 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-sizeb.png")));
74 appendCursor(Qt::SizeAllCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Size All"),
75 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-sizeall.png")));
76 appendCursor(Qt::BlankCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Blank"),
78 appendCursor(Qt::SplitVCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Split Vertical"),
79 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-vsplit.png")));
80 appendCursor(Qt::SplitHCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Split Horizontal"),
81 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-hsplit.png")));
82 appendCursor(Qt::PointingHandCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Pointing Hand"),
83 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-hand.png")));
84 appendCursor(Qt::ForbiddenCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Forbidden"),
85 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-forbidden.png")));
86 appendCursor(Qt::OpenHandCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Open Hand"),
87 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-openhand.png")));
88 appendCursor(Qt::ClosedHandCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Closed Hand"),
89 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-closedhand.png")));
90 appendCursor(Qt::WhatsThisCursor, QCoreApplication::translate(
"QtCursorDatabase",
"What's This"),
91 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-whatsthis.png")));
92 appendCursor(Qt::BusyCursor, QCoreApplication::translate(
"QtCursorDatabase",
"Busy"),
93 QIcon(QLatin1String(
":/qt-project.org/qtpropertybrowser/images/cursor-busy.png")));
98 m_cursorNames.clear();
99 m_cursorIcons.clear();
100 m_valueToCursorShape.clear();
101 m_cursorShapeToValue.clear();
104 void QtCursorDatabase::appendCursor(Qt::CursorShape shape,
const QString& name,
const QIcon& icon)
106 if (m_cursorShapeToValue.contains(shape))
111 const int value = m_cursorNames.count();
112 m_cursorNames.append(name);
113 m_cursorIcons.insert(
value, icon);
114 m_valueToCursorShape.insert(
value, shape);
115 m_cursorShapeToValue.insert(shape,
value);
120 return m_cursorNames;
125 return m_cursorIcons;
134 return m_cursorNames.at(val);
143 return m_cursorIcons.value(val);
149 Qt::CursorShape shape = cursor.shape();
151 if (m_cursorShapeToValue.contains(shape))
153 return m_cursorShapeToValue[shape];
163 if (m_valueToCursorShape.contains(
value))
165 return QCursor(m_valueToCursorShape[
value]);
174 QImage img(16, 16, QImage::Format_ARGB32_Premultiplied);
177 QPainter painter(&img);
178 painter.setCompositionMode(QPainter::CompositionMode_Source);
179 painter.fillRect(0, 0, img.width(), img.height(), b);
180 QColor color = b.color();
182 if (color.alpha() != 255)
184 QBrush opaqueBrush = b;
186 opaqueBrush.setColor(color);
187 painter.fillRect(img.width() / 4, img.height() / 4,
188 img.width() / 2, img.height() / 2, opaqueBrush);
192 return QPixmap::fromImage(img);
202 return QCoreApplication::translate(
"QtPropertyBrowserUtils",
"[%1, %2, %3] (%4)")
203 .arg(
c.red()).arg(
c.green()).arg(
c.blue()).arg(
c.alpha());
209 QImage img(16, 16, QImage::Format_ARGB32_Premultiplied);
212 p.setRenderHint(QPainter::TextAntialiasing,
true);
213 p.setRenderHint(QPainter::Antialiasing,
true);
217 t.setAlignment(Qt::AlignCenter);
218 p.drawText(QRect(0, 0, 16, 16), QString(QLatin1Char(
'A')), t);
219 return QPixmap::fromImage(img);
229 return QCoreApplication::translate(
"QtPropertyBrowserUtils",
"[%1, %2]")
230 .arg(f.family()).arg(f.pointSize());
236 m_checkBox(new QCheckBox(this)),
239 QHBoxLayout* lt =
new QHBoxLayout;
241 if (QApplication::layoutDirection() == Qt::LeftToRight)
243 lt->setContentsMargins(4, 0, 0, 0);
247 lt->setContentsMargins(0, 0, 4, 0);
250 lt->addWidget(m_checkBox);
252 connect(m_checkBox, SIGNAL(
toggled(
bool)),
this, SIGNAL(
toggled(
bool)));
253 setFocusProxy(m_checkBox);
254 m_checkBox->setText(tr(
"True"));
268 m_checkBox->setText(
isChecked() ? tr(
"True") : tr(
"False"));
272 m_checkBox->setText(QString());
278 return m_checkBox->checkState();
283 m_checkBox->setCheckState(state);
288 return m_checkBox->isChecked();
293 m_checkBox->setChecked(
c);
300 m_checkBox->setText(
isChecked() ? tr(
"True") : tr(
"False"));
305 return m_checkBox->blockSignals(block);
310 if (event->buttons() == Qt::LeftButton)
317 QWidget::mousePressEvent(event);
326 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p,
this);
332 : QWidget(parent), m_num(0), m_lineEdit(new QLineEdit(this))
334 QHBoxLayout* layout =
new QHBoxLayout(
this);
335 layout->addWidget(m_lineEdit);
336 layout->setMargin(0);
337 m_lineEdit->installEventFilter(
this);
338 m_lineEdit->setReadOnly(
true);
339 m_lineEdit->setFocusProxy(
this);
340 setFocusPolicy(m_lineEdit->focusPolicy());
341 setAttribute(Qt::WA_InputMethodEnabled);
346 if (o == m_lineEdit && e->type() == QEvent::ContextMenu)
348 QContextMenuEvent*
c =
static_cast<QContextMenuEvent*
>(e);
349 QMenu* menu = m_lineEdit->createStandardContextMenu();
350 const QList<QAction*> actions = menu->actions();
351 QListIterator<QAction*> itAction(actions);
353 while (itAction.hasNext())
355 QAction* action = itAction.next();
356 action->setShortcut(QKeySequence());
357 QString actionString = action->text();
358 const int pos = actionString.lastIndexOf(QLatin1Char(
'\t'));
362 actionString.remove(pos, actionString.length() - pos);
365 action->setText(actionString);
368 QAction* actionBefore = 0;
370 if (actions.count() > 0)
372 actionBefore = actions[0];
375 QAction* clearAction =
new QAction(tr(
"Clear Shortcut"), menu);
376 menu->insertAction(actionBefore, clearAction);
377 menu->insertSeparator(actionBefore);
378 clearAction->setEnabled(!m_keySequence.isEmpty());
379 connect(clearAction, SIGNAL(triggered()),
this, SLOT(slotClearShortcut()));
380 menu->exec(
c->globalPos());
386 return QWidget::eventFilter(o, e);
389 void QtKeySequenceEdit::slotClearShortcut()
391 if (m_keySequence.isEmpty())
400 void QtKeySequenceEdit::handleKeyEvent(QKeyEvent* e)
402 int nextKey = e->key();
404 if (nextKey == Qt::Key_Control || nextKey == Qt::Key_Shift ||
405 nextKey == Qt::Key_Meta || nextKey == Qt::Key_Alt ||
406 nextKey == Qt::Key_Super_L || nextKey == Qt::Key_AltGr)
411 nextKey |= translateModifiers(e->modifiers(), e->text());
412 int k0 = m_keySequence[0];
413 int k1 = m_keySequence[1];
414 int k2 = m_keySequence[2];
415 int k3 = m_keySequence[3];
452 m_keySequence = QKeySequence(k0, k1, k2, k3);
453 m_lineEdit->setText(m_keySequence.toString(QKeySequence::NativeText));
460 if (sequence == m_keySequence)
466 m_keySequence = sequence;
467 m_lineEdit->setText(m_keySequence.toString(QKeySequence::NativeText));
472 return m_keySequence;
475 int QtKeySequenceEdit::translateModifiers(Qt::KeyboardModifiers state,
const QString& text)
const
479 if ((state & Qt::ShiftModifier) && (text.size() == 0 || !text.at(0).isPrint() || text.at(0).isLetter() || text.at(0).isSpace()))
484 if (state & Qt::ControlModifier)
489 if (state & Qt::MetaModifier)
494 if (state & Qt::AltModifier)
504 m_lineEdit->event(e);
505 m_lineEdit->selectAll();
506 QWidget::focusInEvent(e);
512 m_lineEdit->event(e);
513 QWidget::focusOutEvent(e);
524 m_lineEdit->event(e);
532 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p,
this);
537 if (e->type() == QEvent::Shortcut ||
538 e->type() == QEvent::ShortcutOverride ||
539 e->type() == QEvent::KeyRelease)
545 return QWidget::event(e);