void SearchLineWidget::paintEvent(QPaintEvent *e) { e->accept(); QPainter p(this); p.setRenderHint(QPainter::Antialiasing, true); p.setPen(QColor(211, 215, 224)); QRect roundedRect(e->rect().x(), e->rect().y(), e->rect().width(), e->rect().height()); qreal bottomLeftRadius, bottomRightRadius, topLeftRadius, topRightRadius; bottomLeftRadius = bottomRightRadius = topLeftRadius = topRightRadius = 15; QPainterPath path(QPoint(roundedRect.left(), roundedRect.top() + topLeftRadius)); path.quadTo(roundedRect.left(), roundedRect.top(), roundedRect.left() + topLeftRadius, roundedRect.top()); path.lineTo(roundedRect.right() - topRightRadius, roundedRect.top()); path.quadTo(roundedRect.right(), roundedRect.top(), roundedRect.right(), roundedRect.top() + topRightRadius); path.lineTo(roundedRect.right(), roundedRect.bottom() - bottomRightRadius); path.quadTo(roundedRect.right(), roundedRect.bottom(), roundedRect.right() - bottomRightRadius, roundedRect.bottom()); path.lineTo(roundedRect.left() + bottomLeftRadius, roundedRect.bottom()); path.quadTo(roundedRect.left(), roundedRect.bottom(), roundedRect.left(), roundedRect.bottom() - bottomLeftRadius); path.closeSubpath(); p.drawPath(path); QIcon iconAdvSearch(":/actions/advanced_search"); QIcon iconSearch(":/actions/search"); QRect rectAdvSearch(5, 5, e->rect().height()-10, e->rect().height()-10); iconAdvSearch.paint(&p, rectAdvSearch, Qt::AlignCenter); QRect rectSearch(width()-e->rect().height(), 0, e->rect().height(), e->rect().height()); iconSearch.paint(&p, rectSearch, Qt::AlignCenter); }
void ItemEditorWidget::initMenuItems() { Q_ASSERT(m_editor); auto frame = qobject_cast<QFrame*>(m_editor); if (frame) frame->setFrameShape(QFrame::NoFrame); for (auto action : m_toolBar->actions()) delete action; QAction *act; act = new QAction( iconSave(), tr("Save"), m_editor ); m_toolBar->addAction(act); act->setToolTip( tr("Save Item (<strong>F2</strong>)") ); act->setShortcut( QKeySequence(tr("F2", "Shortcut to save item editor changes")) ); connect( act, &QAction::triggered, this, &ItemEditorWidget::saveAndExit ); act = new QAction( iconCancel(), tr("Cancel"), m_editor ); m_toolBar->addAction(act); act->setToolTip( tr("Cancel Editing and Revert Changes") ); act->setShortcut( QKeySequence(tr("Escape", "Shortcut to revert item editor changes")) ); connect( act, &QAction::triggered, this, &ItemEditorWidget::cancel ); auto doc = document(); if (document()) { m_toolBar->addSeparator(); act = new QAction( iconUndo(), tr("Undo"), m_editor ); m_toolBar->addAction(act); act->setShortcut(QKeySequence::Undo); act->setEnabled(false); connect( act, &QAction::triggered, doc, static_cast<void (QTextDocument::*)()>(&QTextDocument::undo) ); connect( doc, &QTextDocument::undoAvailable, act, &QAction::setEnabled ); act = new QAction( iconRedo(), tr("Redo"), m_editor ); m_toolBar->addAction(act); act->setShortcut(QKeySequence::Redo); act->setEnabled(false); connect( act, &QAction::triggered, doc, static_cast<void (QTextDocument::*)()>(&QTextDocument::redo) ); connect( doc, &QTextDocument::redoAvailable, act, &QAction::setEnabled ); m_toolBar->addSeparator(); act = new QAction( iconFont(), tr("Font"), m_editor ); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::setFont ); act = new QAction( iconBold(), tr("Bold"), m_editor ); m_toolBar->addAction(act); act->setShortcut( QKeySequence::Bold ); connect( act, &QAction::triggered, this, &ItemEditorWidget::toggleBoldText ); act = new QAction( iconItalic(), tr("Italic"), m_editor ); m_toolBar->addAction(act); act->setShortcut( QKeySequence::Italic ); connect( act, &QAction::triggered, this, &ItemEditorWidget::toggleItalicText ); act = new QAction( iconUnderline(), tr("Underline"), m_editor ); m_toolBar->addAction(act); act->setShortcut( QKeySequence::Underline ); connect( act, &QAction::triggered, this, &ItemEditorWidget::toggleUnderlineText ); act = new QAction( iconStrikethrough(), tr("Strikethrough"), m_editor ); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::toggleStrikethroughText ); m_toolBar->addSeparator(); act = new QAction( iconForeground(), tr("Foreground"), m_editor ); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::setForeground ); act = new QAction( iconBackground(), tr("Background"), m_editor ); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::setBackground ); m_toolBar->addSeparator(); act = new QAction( iconEraseStyle(), tr("Erase Style"), m_editor ); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::eraseStyle ); m_toolBar->addSeparator(); act = new QAction( iconSearch(), tr("Search"), m_editor ); act->setShortcuts(QKeySequence::Find); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::searchRequest ); } }