mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-01-01 02:58:08 +01:00
Issue #116: Draw dialog title bar
This commit is contained in:
parent
288eead65e
commit
2d1e1dc479
@ -33,7 +33,8 @@
|
||||
#include <QWheelEvent>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
|
||||
#include <QStylePainter>
|
||||
#include <QStyleOptionTitleBar>
|
||||
namespace pdf
|
||||
{
|
||||
|
||||
@ -235,10 +236,39 @@ public:
|
||||
|
||||
virtual bool event(QEvent* event) override;
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
private:
|
||||
PDFDrawWidgetProxy* m_proxy;
|
||||
};
|
||||
|
||||
void PDFFindTextToolDialog::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
QDialog::paintEvent(event);
|
||||
|
||||
QStylePainter painter(this);
|
||||
|
||||
// Dialog rectangle
|
||||
QRect rect = this->rect();
|
||||
const int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
|
||||
QRect titleBarRect = rect;
|
||||
titleBarRect.setHeight(titleBarHeight);
|
||||
|
||||
QStyleOptionTitleBar titleOption;
|
||||
titleOption.initFrom(this);
|
||||
titleOption.text = windowTitle();
|
||||
titleOption.rect = titleBarRect;
|
||||
titleOption.titleBarState = windowState() | Qt::WindowActive;
|
||||
titleOption.titleBarFlags = Qt::Popup | Qt::CustomizeWindowHint | Qt::WindowTitleHint;
|
||||
painter.drawComplexControl(QStyle::CC_TitleBar, titleOption);
|
||||
|
||||
QStyleOptionFrame frameOption;
|
||||
frameOption.initFrom(this);
|
||||
frameOption.rect = QRect(rect.x(), rect.y() + titleBarHeight, rect.width(), rect.height() - titleBarHeight);
|
||||
painter.drawPrimitive(QStyle::PE_Frame, frameOption);
|
||||
}
|
||||
|
||||
bool PDFFindTextToolDialog::event(QEvent* event)
|
||||
{
|
||||
switch (event->type())
|
||||
@ -346,7 +376,7 @@ void PDFFindTextTool::setActiveImpl(bool active)
|
||||
getProxy()->getTextLayoutCompiler()->makeTextLayout();
|
||||
|
||||
// Create dialog
|
||||
m_dialog = new PDFFindTextToolDialog(getProxy(), m_parentDialog, Qt::Popup | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
||||
m_dialog = new PDFFindTextToolDialog(getProxy(), m_parentDialog, Qt::Popup);
|
||||
m_dialog->setWindowTitle(tr("Find"));
|
||||
|
||||
QGridLayout* layout = new QGridLayout(m_dialog);
|
||||
@ -380,6 +410,10 @@ void PDFFindTextTool::setActiveImpl(bool active)
|
||||
connect(m_caseSensitiveCheckBox, &QCheckBox::clicked, this, &PDFFindTextTool::onSearchText);
|
||||
connect(m_wholeWordsCheckBox, &QCheckBox::clicked, this, &PDFFindTextTool::onSearchText);
|
||||
|
||||
QMargins margins = layout->contentsMargins();
|
||||
margins.setTop(margins.top() + m_dialog->style()->pixelMetric(QStyle::PM_TitleBarHeight));
|
||||
layout->setContentsMargins(margins);
|
||||
|
||||
layout->addWidget(new QLabel(tr("Search text"), m_dialog), 0, 0, 1, -1, Qt::AlignLeft);
|
||||
layout->addWidget(m_findTextEdit, 1, 0, 1, -1);
|
||||
layout->addWidget(m_caseSensitiveCheckBox, 2, 0, 1, -1, Qt::AlignLeft);
|
||||
@ -587,6 +621,8 @@ void PDFFindTextTool::updateTitle()
|
||||
{
|
||||
m_dialog->setWindowTitle(tr("Find (%1/%2)").arg(m_selectedResultIndex + 1).arg(m_findResults.size()));
|
||||
}
|
||||
|
||||
m_dialog->update();
|
||||
}
|
||||
|
||||
PDFTextSelection PDFFindTextTool::getTextSelectionImpl() const
|
||||
|
Loading…
Reference in New Issue
Block a user