-ClearButton::ClearButton(QWidget *parent)
- : QAbstractButton(parent)
-{
- setCursor(Qt::ArrowCursor);
- setToolTip(tr("Clear"));
- setVisible(false);
- setFocusPolicy(Qt::NoFocus);
-}
-
-void ClearButton::paintEvent(QPaintEvent *event)
-{
- Q_UNUSED(event);
- QPainter painter(this);
- int height = this->height();
-
- painter.setRenderHint(QPainter::Antialiasing, true);
- // QColor color = palette().color(QPalette::Mid);
- painter.setBrush(isDown()
- ? palette().color(QPalette::Dark)
- : palette().color(QPalette::Mid));
- painter.setPen(painter.brush().color());
- int size = width();
- int offset = size / 3.5;
- int radius = size - offset * 2;
- painter.drawEllipse(offset, offset, radius, radius);
-
- painter.setPen(QPen(palette().color(QPalette::Base),2));
- int border = offset * 1.6;
- painter.drawLine(border, border, width() - border, height - border);
- painter.drawLine(border, height - border, width() - border, border);
-}
-
-void ClearButton::textChanged(const QString &text)
-{
- setVisible(!text.isEmpty());
-}
-
-/*
- Search icon on the left hand side of the search widget
- When a menu is set a down arrow appears
- */
-class SearchButton : public QAbstractButton {
-public:
- SearchButton(QWidget *parent = 0);
- void paintEvent(QPaintEvent *event);
- QMenu *m_menu;
-
-protected:
- void mousePressEvent(QMouseEvent *event);
-};
-
-SearchButton::SearchButton(QWidget *parent)
- : QAbstractButton(parent),
- m_menu(0)
-{
- setObjectName(QLatin1String("SearchButton"));
- setCursor(Qt::ArrowCursor);
- setFocusPolicy(Qt::NoFocus);
-}
-
-void SearchButton::mousePressEvent(QMouseEvent *event)
-{
- if (m_menu && event->button() == Qt::LeftButton) {
- QWidget *p = parentWidget();
- if (p) {
- QPoint r = p->mapToGlobal(QPoint(0, p->height()));
- m_menu->exec(QPoint(r.x() + height() / 2, r.y()));
- }
- event->accept();
- }
- QAbstractButton::mousePressEvent(event);
-}
-
-void SearchButton::paintEvent(QPaintEvent *event)
-{
- Q_UNUSED(event);
- QPainterPath myPath;