-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprojcontrollerpane.cpp
More file actions
executable file
·135 lines (115 loc) · 4.63 KB
/
projcontrollerpane.cpp
File metadata and controls
executable file
·135 lines (115 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Copyright 2016 Pascal COMBES <pascom@orange.fr>
*
* This file is part of ProSlideShower.
*
* ProSlideShower is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ProSlideShower is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProSlideShower. If not, see <http://www.gnu.org/licenses/>
*/
#include "projcontrollerpane.h"
#include "presmodel.h"
#include "galleryview.h"
#if QT_VERSION > 0x050000
# include <QtWidgets>
#else
# include <QtGui>
#endif
ProjControllerPane::ProjControllerPane(QWidget *parent) :
QWidget(parent)
{
mSlidesView = new GalleryView(Qt::Horizontal, this);
mSlidesView->setTopPadding(1, 2);
mSlidesView->setBottomPadding(1, 2);
mSlidesView->setLeftPadding(1, 2);
mSlidesView->setRightPadding(1, 2);
mSlidesView->setTopMargin(1, 2);
mSlidesView->setBottomMargin(1, 2);
mSlidesView->setLeftMargin(5);
mSlidesView->setRightMargin(5);
mSlidesView->setSpacing(5);
mSlidesView->setSelectionMode(QAbstractItemView::SingleSelection);
mOpenButton = new QToolButton(this);
mOpenButton->setIcon(QIcon(":/icons/open.png"));
mOpenButton->setToolTip(tr("Open master"));
mOpenButton->installEventFilter(this);
mConfigButton = new QToolButton(this);
mConfigButton->setIcon(QIcon(":/icons/configure.png"));
mConfigButton->setToolTip(tr("Configure"));
mConfigButton->installEventFilter(this);
mCloseButton = new QToolButton(this);
mCloseButton->setIcon(QIcon(":/icons/close.png"));
mCloseButton->setToolTip(tr("Quit"));
mCloseButton->installEventFilter(this);
QBoxLayout *leftButtonLayout = new QVBoxLayout;
leftButtonLayout->setContentsMargins(0, 0, 0, 0);
leftButtonLayout->addWidget(mOpenButton);
leftButtonLayout->addStretch(1);
QBoxLayout *rightButtonLayout = new QVBoxLayout;
rightButtonLayout->setContentsMargins(0, 0, 0, 0);
rightButtonLayout->addWidget(mCloseButton);
rightButtonLayout->addWidget(mConfigButton);
rightButtonLayout->addStretch(1);
QBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->setContentsMargins(6, 6, 6, 0);
mainLayout->addLayout(leftButtonLayout);
mainLayout->addWidget(mSlidesView, 1);
mainLayout->addLayout(rightButtonLayout);
setLayout(mainLayout);
connect(mCloseButton, SIGNAL(clicked(bool)),
qApp, SLOT(quit()));
connect(mOpenButton, SIGNAL(clicked(bool)),
this, SIGNAL(openDocumentRequest()));
connect(mConfigButton, SIGNAL(clicked(bool)),
this, SIGNAL(configureRequest()));
}
void ProjControllerPane::setModel(PresModel *model)
{
if (mSlidesView->model() != NULL) {
disconnect(mSlidesView, SIGNAL(doubleClicked(const QModelIndex&)),
mSlidesView->model(), SLOT(setCurrentPage(const QModelIndex&)));
disconnect(mSlidesView->model(), SIGNAL(currentPageChanged()),
this, SIGNAL(handlePageChange()));
disconnect(mSlidesView->model(), SIGNAL(modelReset()),
this, SLOT(handlePageChange()));
}
mSlidesView->setModel(model);
if (model == NULL)
return;
mSlidesView->setCurrentIndex(model->getCurentIndex());
mSlidesView->center(model->getCurentIndex());
connect(mSlidesView, SIGNAL(doubleClicked(const QModelIndex&)),
model, SLOT(setCurrentPage(const QModelIndex&)));
connect(model, SIGNAL(currentPageChanged()),
this, SLOT(handlePageChange()));
connect(model, SIGNAL(modelReset()),
this, SLOT(handlePageChange()));
}
void ProjControllerPane::handlePageChange(void)
{
PresModel *presModel = qobject_cast<PresModel *>(mSlidesView->model());
if (presModel != NULL) {
mSlidesView->setCurrentIndex(presModel->getCurentIndex());
mSlidesView->center(presModel->getCurentIndex());
}
}
bool ProjControllerPane::eventFilter(QObject* watched, QEvent* event)
{
QWidget *watchedWidget = qobject_cast<QWidget*>(watched);
if (watched == NULL)
return false;
if ((event->type() == QEvent::HoverEnter)
|| (event->type() == QEvent::HoverMove)) {
QHoverEvent *he = static_cast<QHoverEvent*>(event);
QToolTip::showText(watchedWidget->mapToGlobal(he->pos()), watchedWidget->toolTip(), watchedWidget, watchedWidget->rect());
}
return false;
}