mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2024-12-27 08:42:48 +01:00
Issue #97: Context menu + layout items on window size changed
This commit is contained in:
parent
c57f28a3b5
commit
10f24c2dff
@ -56,6 +56,8 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
|
||||
ui->documentItemsView->setModel(m_model);
|
||||
ui->documentItemsView->setItemDelegate(m_delegate);
|
||||
connect(ui->documentItemsView, &QListView::customContextMenuRequested, this, &MainWindow::onWorkspaceCustomContextMenuRequested);
|
||||
|
||||
setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(800, 600)));
|
||||
|
||||
ui->actionClear->setData(int(Operation::Clear));
|
||||
@ -221,6 +223,13 @@ QSize MainWindow::getMaxPageImageSize() const
|
||||
return pdf::PDFWidgetUtils::scaleDPI(this, QSize(250, 250));
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent* resizeEvent)
|
||||
{
|
||||
QMainWindow::resizeEvent(resizeEvent);
|
||||
|
||||
ui->documentItemsView->doItemsLayout();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionClose_triggered()
|
||||
{
|
||||
close();
|
||||
@ -246,6 +255,35 @@ void MainWindow::onMappedActionTriggered(int actionId)
|
||||
performOperation(static_cast<Operation>(actionId));
|
||||
}
|
||||
|
||||
void MainWindow::onWorkspaceCustomContextMenuRequested(const QPoint& point)
|
||||
{
|
||||
QMenu* contextMenu = new QMenu(this);
|
||||
contextMenu->addAction(ui->actionCut);
|
||||
contextMenu->addAction(ui->actionCopy);
|
||||
contextMenu->addAction(ui->actionPaste);
|
||||
contextMenu->addSeparator();
|
||||
contextMenu->addAction(ui->actionRotate_Left);
|
||||
contextMenu->addAction(ui->actionRotate_Right);
|
||||
QMenu* selectMenu = contextMenu->addMenu(tr("Select"));
|
||||
selectMenu->addAction(ui->actionSelect_All);
|
||||
selectMenu->addAction(ui->actionSelect_Even);
|
||||
selectMenu->addAction(ui->actionSelect_Odd);
|
||||
selectMenu->addAction(ui->actionSelect_Landscape);
|
||||
selectMenu->addAction(ui->actionSelect_Portrait);
|
||||
selectMenu->addAction(ui->actionSelect_None);
|
||||
QMenu* regroupMenu = contextMenu->addMenu(tr("Regroup"));
|
||||
regroupMenu->addAction(ui->actionRegroup_Even_Odd);
|
||||
regroupMenu->addAction(ui->actionRegroup_by_Alternating_Pages);
|
||||
regroupMenu->addAction(ui->actionRegroup_by_Alternating_Pages_Reversed_Order);
|
||||
regroupMenu->addAction(ui->actionRegroup_by_Page_Pairs);
|
||||
regroupMenu->addAction(ui->actionRegroup_by_Bookmarks);
|
||||
contextMenu->addSeparator();
|
||||
contextMenu->addAction(ui->actionGroup);
|
||||
contextMenu->addAction(ui->actionUngroup);
|
||||
|
||||
contextMenu->exec(ui->documentItemsView->viewport()->mapToGlobal(point));
|
||||
}
|
||||
|
||||
void MainWindow::updateActions()
|
||||
{
|
||||
QList<QAction*> actions = findChildren<QAction*>();
|
||||
|
@ -100,10 +100,14 @@ public:
|
||||
PrepareIconTheme
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent* resizeEvent) override;
|
||||
|
||||
private slots:
|
||||
void on_actionClose_triggered();
|
||||
void on_actionAddDocuments_triggered();
|
||||
void onMappedActionTriggered(int actionId);
|
||||
void onWorkspaceCustomContextMenuRequested(const QPoint& point);
|
||||
void updateActions();
|
||||
|
||||
private:
|
||||
|
@ -20,6 +20,9 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QListView" name="documentItemsView">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
@ -83,10 +83,25 @@ QVariant PageItemModel::data(const QModelIndex& index, int role) const
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const PageGroupItem* item = getItem(index);
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
return m_pageGroupItems.at(index.row()).groupName;
|
||||
return item->groupName;
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
{
|
||||
QStringList texts;
|
||||
texts << QString("<b>%1</b>").arg(item->groupName);
|
||||
|
||||
if (item->isGrouped())
|
||||
{
|
||||
texts << QString("%1 pages").arg(item->groups.size());
|
||||
}
|
||||
|
||||
return texts.join("<br>");
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user