pineapple-pictures/mainwindow.cpp

634 lines
21 KiB
C++
Raw Normal View History

2019-09-28 01:18:08 +08:00
#include "mainwindow.h"
2019-10-06 14:12:52 +08:00
#include "toolbutton.h"
2019-09-29 01:40:19 +08:00
#include "bottombuttongroup.h"
2019-09-28 01:18:08 +08:00
#include "graphicsview.h"
2019-10-03 17:57:14 +08:00
#include "navigatorview.h"
2019-09-29 15:52:35 +08:00
#include "graphicsscene.h"
2019-09-28 01:18:08 +08:00
#include <QMouseEvent>
#include <QMovie>
#include <QDebug>
#include <QGraphicsTextItem>
2019-09-29 01:40:19 +08:00
#include <QApplication>
2019-09-29 15:52:35 +08:00
#include <QStyle>
#include <QScreen>
2019-10-05 13:21:49 +08:00
#include <QMenu>
2019-11-03 17:15:50 +08:00
#include <QShortcut>
#include <QDir>
#include <QCollator>
#include <QClipboard>
#include <QMimeData>
2019-09-29 01:40:19 +08:00
#ifdef _WIN32
#include <windows.h>
#endif // _WIN32
2019-09-28 01:18:08 +08:00
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
2019-10-02 22:16:20 +08:00
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
2019-09-28 01:18:08 +08:00
this->setAttribute(Qt::WA_TranslucentBackground, true);
2020-07-27 20:47:54 +08:00
this->setMinimumSize(350, 350);
2019-10-01 11:44:35 +08:00
this->setWindowIcon(QIcon(":/icons/app-icon.svg"));
2020-07-04 13:49:12 +08:00
this->setMouseTracking(true);
2019-09-28 01:18:08 +08:00
m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity");
m_fadeOutAnimation->setDuration(300);
m_fadeOutAnimation->setStartValue(1);
m_fadeOutAnimation->setEndValue(0);
m_floatUpAnimation = new QPropertyAnimation(this, "geometry");
m_floatUpAnimation->setDuration(300);
m_floatUpAnimation->setEasingCurve(QEasingCurve::OutCirc);
m_exitAnimationGroup = new QParallelAnimationGroup;
m_exitAnimationGroup->addAnimation(m_fadeOutAnimation);
m_exitAnimationGroup->addAnimation(m_floatUpAnimation);
connect(m_exitAnimationGroup, &QParallelAnimationGroup::finished,
this, &QMainWindow::close);
2019-09-29 15:52:35 +08:00
GraphicsScene * scene = new GraphicsScene(this);
2019-09-28 01:18:08 +08:00
m_graphicsView = new GraphicsView(this);
m_graphicsView->setScene(scene);
this->setCentralWidget(m_graphicsView);
2019-09-28 01:18:08 +08:00
2019-10-03 17:57:14 +08:00
m_gv = new NavigatorView(this);
2019-10-04 21:34:20 +08:00
m_gv->setFixedSize(220, 160);
2019-10-03 17:57:14 +08:00
m_gv->setScene(scene);
2019-10-04 09:54:13 +08:00
m_gv->setMainView(m_graphicsView);
2019-10-03 17:57:14 +08:00
m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
connect(m_graphicsView, &GraphicsView::navigatorViewRequired,
this, [ = ](bool required, qreal angle){
m_gv->resetTransform();
m_gv->rotate(angle);
m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
m_gv->setVisible(required);
m_gv->updateMainViewportRegion();
2019-10-03 17:57:14 +08:00
});
2019-10-04 09:54:13 +08:00
connect(m_graphicsView, &GraphicsView::viewportRectChanged,
m_gv, &NavigatorView::updateMainViewportRegion);
connect(m_graphicsView, &GraphicsView::requestGallery,
this, &MainWindow::loadGalleryBySingleLocalFile);
2020-07-04 13:49:12 +08:00
m_closeButton = new ToolButton(true, m_graphicsView);
2019-10-06 14:12:52 +08:00
m_closeButton->setIcon(QIcon(":/icons/window-close"));
m_closeButton->setIconSize(QSize(50, 50));
2019-09-28 01:18:08 +08:00
connect(m_closeButton, &QAbstractButton::clicked,
this, &MainWindow::closeWindow);
2019-09-29 01:40:19 +08:00
2020-07-04 13:49:12 +08:00
m_prevButton = new ToolButton(false, m_graphicsView);
m_prevButton->setIcon(QIcon(":/icons/go-previous"));
m_prevButton->setIconSize(QSize(75, 75));
m_prevButton->setVisible(false);
m_prevButton->setOpacity(0, false);
m_nextButton = new ToolButton(false, m_graphicsView);
m_nextButton->setIcon(QIcon(":/icons/go-next"));
m_nextButton->setIconSize(QSize(75, 75));
m_nextButton->setVisible(false);
m_nextButton->setOpacity(0, false);
connect(m_prevButton, &QAbstractButton::clicked,
this, &MainWindow::galleryPrev);
connect(m_nextButton, &QAbstractButton::clicked,
this, &MainWindow::galleryNext);
2019-09-29 01:40:19 +08:00
m_bottomButtonGroup = new BottomButtonGroup(this);
2019-09-29 15:52:35 +08:00
2019-09-30 23:02:44 +08:00
connect(m_bottomButtonGroup, &BottomButtonGroup::resetToOriginalBtnClicked,
2019-10-02 16:04:50 +08:00
this, [ = ](){ m_graphicsView->resetScale(); });
2019-10-04 21:34:20 +08:00
connect(m_bottomButtonGroup, &BottomButtonGroup::toggleWindowMaximum,
this, [ = ](){
if (isMaximized()) {
showNormal();
} else {
showMaximized();
}
});
2019-09-30 23:02:44 +08:00
connect(m_bottomButtonGroup, &BottomButtonGroup::zoomInBtnClicked,
2019-10-02 16:04:50 +08:00
this, [ = ](){ m_graphicsView->zoomView(1.25); });
2019-09-30 23:02:44 +08:00
connect(m_bottomButtonGroup, &BottomButtonGroup::zoomOutBtnClicked,
2019-10-02 16:04:50 +08:00
this, [ = ](){ m_graphicsView->zoomView(0.75); });
2019-09-30 23:02:44 +08:00
connect(m_bottomButtonGroup, &BottomButtonGroup::toggleCheckerboardBtnClicked,
this, [ = ](){ m_graphicsView->toggleCheckerboard(); });
2019-10-02 14:31:24 +08:00
connect(m_bottomButtonGroup, &BottomButtonGroup::rotateRightBtnClicked,
this, [ = ](){
2019-10-02 16:04:50 +08:00
m_graphicsView->resetScale();
m_graphicsView->rotateView(90);
2019-10-02 14:31:24 +08:00
m_graphicsView->checkAndDoFitInView();
2019-10-03 17:57:14 +08:00
m_gv->setVisible(false);
2019-10-02 14:31:24 +08:00
});
2019-09-30 23:02:44 +08:00
2019-10-06 14:58:01 +08:00
m_bottomButtonGroup->setOpacity(0, false);
m_gv->setOpacity(0, false);
m_closeButton->setOpacity(0, false);
2019-10-03 11:00:28 +08:00
2020-07-04 13:49:12 +08:00
connect(this, &MainWindow::galleryLoaded, this, [this]() {
m_prevButton->setVisible(isGalleryAvailable());
m_nextButton->setVisible(isGalleryAvailable());
});
2019-11-03 17:15:50 +08:00
QShortcut * quitAppShorucut = new QShortcut(QKeySequence(Qt::Key_Space), this);
connect(quitAppShorucut, &QShortcut::activated,
std::bind(&MainWindow::quitAppAction, this, false));
QShortcut * quitAppShorucut2 = new QShortcut(QKeySequence(Qt::Key_Escape), this);
connect(quitAppShorucut2, &QShortcut::activated,
std::bind(&MainWindow::quitAppAction, this, false));
QShortcut * prevPictureShorucut = new QShortcut(QKeySequence(Qt::Key_PageUp), this);
connect(prevPictureShorucut, &QShortcut::activated,
this, &MainWindow::galleryPrev);
QShortcut * nextPictureShorucut = new QShortcut(QKeySequence(Qt::Key_PageDown), this);
connect(nextPictureShorucut, &QShortcut::activated,
this, &MainWindow::galleryNext);
2020-05-19 14:08:29 +08:00
QShortcut * fullscreenShorucut = new QShortcut(QKeySequence(QKeySequence::FullScreen), this);
connect(fullscreenShorucut, &QShortcut::activated,
this, &MainWindow::toggleFullscreen);
2019-10-01 11:44:35 +08:00
centerWindow();
2019-09-28 01:18:08 +08:00
}
MainWindow::~MainWindow()
{
}
void MainWindow::showUrls(const QList<QUrl> &urls)
{
if (!urls.isEmpty()) {
if (urls.count() == 1) {
m_graphicsView->showFileFromUrl(urls.first(), true);
} else {
m_graphicsView->showFileFromUrl(urls.first(), false);
m_files = urls;
m_currentFileIndex = 0;
}
} else {
m_graphicsView->showText(tr("File url list is empty"));
return;
}
2019-10-03 17:57:14 +08:00
m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
}
2019-10-01 11:44:35 +08:00
void MainWindow::adjustWindowSizeBySceneRect()
{
QSize sceneSize = m_graphicsView->sceneRect().toRect().size();
QSize sceneSizeWithMargins = sceneSize + QSize(130, 125);
if (m_graphicsView->scaleFactor() < 1 || size().expandedTo(sceneSizeWithMargins) != size()) {
2019-10-01 11:44:35 +08:00
// if it scaled down by the resize policy:
QSize screenSize = qApp->screenAt(QCursor::pos())->availableSize();
if (screenSize.expandedTo(sceneSize) == screenSize) {
// we can show the picture by increase the window size.
2020-07-27 20:47:54 +08:00
QSize finalSize = (screenSize.expandedTo(sceneSizeWithMargins) == screenSize) ?
sceneSizeWithMargins : screenSize;
// We have a very reasonable sizeHint() value ;P
this->resize(finalSize.expandedTo(this->sizeHint()));
2019-10-05 12:55:09 +08:00
// We're sure the window can display the whole thing with 1:1 scale.
// The old window size may cause fitInView call from resize() and the
// above resize() call won't reset the scale back to 1:1, so we
// just call resetScale() here to ensure the thing is no longer scaled.
m_graphicsView->resetScale();
2019-10-01 11:44:35 +08:00
centerWindow();
} else {
// toggle maximum
showMaximized();
}
}
}
// can be empty if it is NOT from a local file.
QUrl MainWindow::currentImageFileUrl() const
{
if (m_currentFileIndex != -1) {
return m_files.value(m_currentFileIndex);
}
return QUrl();
}
void MainWindow::clearGallery()
{
m_currentFileIndex = -1;
m_files.clear();
}
void MainWindow::loadGalleryBySingleLocalFile(const QString &path)
{
QFileInfo info(path);
QDir dir(info.path());
QString currentFileName = info.fileName();
2020-02-24 19:48:22 +08:00
QStringList entryList = dir.entryList({"*.jpg", "*.jpeg", "*.jfif", "*.png", "*.gif", "*.svg", "*.bmp"},
QDir::Files | QDir::NoSymLinks, QDir::NoSort);
QCollator collator;
collator.setNumericMode(true);
std::sort(entryList.begin(), entryList.end(), collator);
clearGallery();
for (int i = 0; i < entryList.count(); i++) {
const QString & oneEntry = entryList.at(i);
m_files.append(QUrl::fromLocalFile(dir.absoluteFilePath(oneEntry)));
if (oneEntry == currentFileName) {
m_currentFileIndex = i;
}
}
2020-07-04 13:49:12 +08:00
emit galleryLoaded();
}
void MainWindow::galleryPrev()
{
int count = m_files.count();
2020-07-04 13:49:12 +08:00
if (!isGalleryAvailable()) {
return;
}
m_currentFileIndex = m_currentFileIndex - 1 < 0 ? count - 1 : m_currentFileIndex - 1;
m_graphicsView->showFileFromUrl(m_files.at(m_currentFileIndex), false);
}
void MainWindow::galleryNext()
{
int count = m_files.count();
2020-07-04 13:49:12 +08:00
if (!isGalleryAvailable()) {
return;
}
m_currentFileIndex = m_currentFileIndex + 1 == count ? 0 : m_currentFileIndex + 1;
m_graphicsView->showFileFromUrl(m_files.at(m_currentFileIndex), false);
}
2020-07-04 13:49:12 +08:00
bool MainWindow::isGalleryAvailable()
{
if (m_currentFileIndex < 0 || m_files.isEmpty() || m_currentFileIndex >= m_files.count()) {
return false;
}
return true;
}
2019-09-29 01:40:19 +08:00
void MainWindow::showEvent(QShowEvent *event)
{
updateWidgetsPosition();
return QMainWindow::showEvent(event);
}
2019-10-03 11:00:28 +08:00
void MainWindow::enterEvent(QEvent *event)
{
2019-10-06 14:58:01 +08:00
m_bottomButtonGroup->setOpacity(1);
m_gv->setOpacity(1);
2019-10-03 11:00:28 +08:00
2019-10-06 14:58:01 +08:00
m_closeButton->setOpacity(1);
2020-07-04 13:49:12 +08:00
m_prevButton->setOpacity(1);
m_nextButton->setOpacity(1);
2019-10-06 14:12:52 +08:00
2019-10-03 11:00:28 +08:00
return QMainWindow::enterEvent(event);
}
void MainWindow::leaveEvent(QEvent *event)
{
2019-10-06 14:58:01 +08:00
m_bottomButtonGroup->setOpacity(0);
m_gv->setOpacity(0);
2019-10-03 11:00:28 +08:00
2019-10-06 14:58:01 +08:00
m_closeButton->setOpacity(0);
2020-07-04 13:49:12 +08:00
m_prevButton->setOpacity(0);
m_nextButton->setOpacity(0);
2019-10-06 14:12:52 +08:00
2019-10-03 11:00:28 +08:00
return QMainWindow::leaveEvent(event);
}
2019-09-28 01:18:08 +08:00
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton && !isMaximized()) {
2019-09-28 01:18:08 +08:00
m_clickedOnWindow = true;
m_oldMousePos = event->pos();
// qDebug() << m_oldMousePos << m_graphicsView->transform().m11()
// << m_graphicsView->transform().m22() << m_graphicsView->matrix().m12();
2019-09-28 01:18:08 +08:00
event->accept();
}
return QMainWindow::mousePressEvent(event);
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow) {
move(event->globalPos() - m_oldMousePos);
event->accept();
}
return QMainWindow::mouseMoveEvent(event);
}
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
m_clickedOnWindow = false;
return QMainWindow::mouseReleaseEvent(event);
}
void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
{
2019-11-03 17:15:50 +08:00
quitAppAction();
2019-09-28 01:18:08 +08:00
return QMainWindow::mouseDoubleClickEvent(event);
}
2019-10-04 09:54:13 +08:00
void MainWindow::wheelEvent(QWheelEvent *event)
{
2020-07-12 23:45:49 +08:00
QPoint numDegrees = event->angleDelta() / 8;
bool needZoom = false, zoomIn = false;
// NOTE: Only checking angleDelta since the QWheelEvent::pixelDelta() doc says
// pixelDelta() value is driver specific and unreliable on X11...
// We are not scrolling the canvas, just zoom in or out, so it probably
// doesn't matter here.
if (!numDegrees.isNull() && numDegrees.y() != 0) {
needZoom = true;
zoomIn = numDegrees.y() > 0;
}
if (needZoom) {
m_graphicsView->zoomView(zoomIn ? 1.25 : 0.8);
event->accept();
2019-10-04 09:54:13 +08:00
} else {
2020-07-12 23:45:49 +08:00
QMainWindow::wheelEvent(event);
2019-10-04 09:54:13 +08:00
}
}
2019-09-28 01:18:08 +08:00
void MainWindow::resizeEvent(QResizeEvent *event)
{
2019-09-29 01:40:19 +08:00
updateWidgetsPosition();
2019-09-28 01:18:08 +08:00
return QMainWindow::resizeEvent(event);
}
2019-10-05 13:21:49 +08:00
void MainWindow::contextMenuEvent(QContextMenuEvent *event)
{
QMenu * menu = new QMenu;
QMenu * copyMenu = new QMenu(tr("&Copy"));
QUrl currentFileUrl = currentImageFileUrl();
QImage clipboardImage;
QUrl clipboardFileUrl;
const QMimeData * clipboardData = QApplication::clipboard()->mimeData();
if (clipboardData->hasImage()) {
QVariant imageVariant(clipboardData->imageData());
if (imageVariant.isValid()) {
clipboardImage = qvariant_cast<QImage>(imageVariant);
}
} else if (clipboardData->hasText()) {
QString clipboardText(clipboardData->text());
if (clipboardText.startsWith("PICTURE:")) {
QString maybeFilename(clipboardText.mid(8));
if (QFile::exists(maybeFilename)) {
clipboardFileUrl = QUrl::fromLocalFile(maybeFilename);
}
}
}
2020-01-05 15:07:08 +08:00
QAction * copyPixmap = new QAction(tr("Copy P&ixmap"));
connect(copyPixmap, &QAction::triggered, this, [ = ](){
QClipboard *cb = QApplication::clipboard();
cb->setPixmap(m_graphicsView->scene()->renderToPixmap());
});
QAction * copyFilePath = new QAction(tr("Copy &File Path"));
connect(copyFilePath, &QAction::triggered, this, [ = ](){
QClipboard *cb = QApplication::clipboard();
cb->setText(currentFileUrl.toLocalFile());
});
copyMenu->addAction(copyPixmap);
if (currentFileUrl.isValid()) {
copyMenu->addAction(copyFilePath);
}
QAction * pasteImage = new QAction(tr("&Paste Image"));
connect(pasteImage, &QAction::triggered, this, [ = ](){
clearGallery();
m_graphicsView->showImage(clipboardImage);
});
QAction * pasteImageFile = new QAction(tr("&Paste Image File"));
connect(pasteImageFile, &QAction::triggered, this, [ = ](){
m_graphicsView->showFileFromUrl(clipboardFileUrl, true);
});
2019-10-06 12:57:38 +08:00
QAction * stayOnTopMode = new QAction(tr("Stay on top"));
connect(stayOnTopMode, &QAction::triggered, this, [ = ](){
toggleStayOnTop();
});
stayOnTopMode->setCheckable(true);
stayOnTopMode->setChecked(stayOnTop());
2019-10-05 13:21:49 +08:00
QAction * protectedMode = new QAction(tr("Protected mode"));
connect(protectedMode, &QAction::triggered, this, [ = ](){
toggleProtectedMode();
});
protectedMode->setCheckable(true);
protectedMode->setChecked(m_protectedMode);
QAction * helpAction = new QAction(tr("Help"));
connect(helpAction, &QAction::triggered, this, [ = ](){
QStringList sl {
tr("Launch application with image file path as argument to load the file."),
tr("Drag and drop image file onto the window is also supported."),
"",
tr("Context menu option explanation:"),
(tr("Stay on top") + " : " + tr("Make window stay on top of all other windows.")),
(tr("Protected mode") + " : " + tr("Avoid close window accidentally. (eg. by double clicking the window)"))
};
m_graphicsView->showText(sl.join('\n'));
});
if (copyMenu->actions().count() == 1) {
menu->addActions(copyMenu->actions());
} else {
menu->addMenu(copyMenu);
}
if (!clipboardImage.isNull()) {
menu->addAction(pasteImage);
} else if (clipboardFileUrl.isValid()) {
menu->addAction(pasteImageFile);
}
menu->addSeparator();
2019-10-06 12:57:38 +08:00
menu->addAction(stayOnTopMode);
2019-10-05 13:21:49 +08:00
menu->addAction(protectedMode);
menu->addSeparator();
menu->addAction(helpAction);
2019-10-05 13:21:49 +08:00
menu->exec(mapToGlobal(event->pos()));
menu->deleteLater();
return QMainWindow::contextMenuEvent(event);
}
2019-09-29 01:40:19 +08:00
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
#ifdef _WIN32
2019-10-03 17:57:14 +08:00
// https://stackoverflow.com/questions/43505580/qt-windows-resizable-frameless-window
2019-09-29 01:40:19 +08:00
// Too lazy to do this now.. just stackoverflow it and did a copy and paste..
2019-10-06 14:58:01 +08:00
Q_UNUSED(eventType)
2019-09-29 01:40:19 +08:00
MSG* msg = static_cast<MSG*>(message);
if (msg->message == WM_NCHITTEST) {
if (isMaximized()) {
return false;
}
*result = 0;
const LONG borderWidth = 8;
RECT winrect;
GetWindowRect(reinterpret_cast<HWND>(winId()), &winrect);
// must be short to correctly work with multiple monitors (negative coordinates)
short x = msg->lParam & 0x0000FFFF;
short y = (msg->lParam & 0xFFFF0000) >> 16;
bool resizeWidth = minimumWidth() != maximumWidth();
bool resizeHeight = minimumHeight() != maximumHeight();
if (resizeWidth) {
//left border
if (x >= winrect.left && x < winrect.left + borderWidth) {
*result = HTLEFT;
}
//right border
if (x < winrect.right && x >= winrect.right - borderWidth) {
*result = HTRIGHT;
}
}
if (resizeHeight) {
//bottom border
if (y < winrect.bottom && y >= winrect.bottom - borderWidth) {
*result = HTBOTTOM;
}
//top border
if (y >= winrect.top && y < winrect.top + borderWidth) {
*result = HTTOP;
}
}
if (resizeWidth && resizeHeight) {
//bottom left corner
if (x >= winrect.left && x < winrect.left + borderWidth &&
y < winrect.bottom && y >= winrect.bottom - borderWidth)
{
*result = HTBOTTOMLEFT;
}
//bottom right corner
if (x < winrect.right && x >= winrect.right - borderWidth &&
y < winrect.bottom && y >= winrect.bottom - borderWidth)
{
*result = HTBOTTOMRIGHT;
}
//top left corner
if (x >= winrect.left && x < winrect.left + borderWidth &&
y >= winrect.top && y < winrect.top + borderWidth)
{
*result = HTTOPLEFT;
}
//top right corner
if (x < winrect.right && x >= winrect.right - borderWidth &&
y >= winrect.top && y < winrect.top + borderWidth)
{
*result = HTTOPRIGHT;
}
}
if (*result != 0)
return true;
QWidget *action = QApplication::widgetAt(QCursor::pos());
if (action == this) {
*result = HTCAPTION;
return true;
}
}
return false;
#else
2019-09-29 09:31:18 +08:00
return QMainWindow::nativeEvent(eventType, message, result);
2019-09-29 01:40:19 +08:00
#endif // _WIN32
}
2020-07-27 20:47:54 +08:00
QSize MainWindow::sizeHint() const
{
return QSize(710, 530);
}
2019-10-01 11:44:35 +08:00
void MainWindow::centerWindow()
{
this->setGeometry(
QStyle::alignedRect(
Qt::LeftToRight,
Qt::AlignCenter,
this->size(),
qApp->screenAt(QCursor::pos())->geometry()
)
);
}
2019-09-28 01:18:08 +08:00
void MainWindow::closeWindow()
{
QRect windowRect(this->geometry());
m_floatUpAnimation->setStartValue(windowRect);
m_floatUpAnimation->setEndValue(windowRect.adjusted(0, -80, 0, 0));
m_floatUpAnimation->setStartValue(QRect(this->geometry().x(), this->geometry().y(), this->geometry().width(), this->geometry().height()));
m_floatUpAnimation->setEndValue(QRect(this->geometry().x(), this->geometry().y()-80, this->geometry().width(), this->geometry().height()));
m_exitAnimationGroup->start();
}
2019-09-29 01:40:19 +08:00
void MainWindow::updateWidgetsPosition()
{
m_closeButton->move(width() - m_closeButton->width(), 0);
2020-07-04 13:49:12 +08:00
m_prevButton->move(25, (height() - m_prevButton->height()) / 2);
m_nextButton->move(width() - m_nextButton->width() - 25,
(height() - m_prevButton->height()) / 2);
2019-09-29 01:40:19 +08:00
m_bottomButtonGroup->move((width() - m_bottomButtonGroup->width()) / 2,
height() - m_bottomButtonGroup->height());
2019-10-03 17:57:14 +08:00
m_gv->move(width() - m_gv->width(), height() - m_gv->height());
2019-09-29 01:40:19 +08:00
}
2019-10-05 13:21:49 +08:00
void MainWindow::toggleProtectedMode()
{
m_protectedMode = !m_protectedMode;
m_closeButton->setVisible(!m_protectedMode);
2020-07-04 13:49:12 +08:00
m_prevButton->setVisible(!m_protectedMode);
m_nextButton->setVisible(!m_protectedMode);
2019-10-05 13:21:49 +08:00
}
2019-10-06 12:57:38 +08:00
void MainWindow::toggleStayOnTop()
{
setWindowFlag(Qt::WindowStaysOnTopHint, !stayOnTop());
show();
2019-10-06 12:57:38 +08:00
}
bool MainWindow::stayOnTop()
{
return windowFlags().testFlag(Qt::WindowStaysOnTopHint);
}
2019-11-03 17:15:50 +08:00
void MainWindow::quitAppAction(bool force)
{
if (!m_protectedMode || force) {
closeWindow();
}
}
2020-05-19 14:08:29 +08:00
void MainWindow::toggleFullscreen()
{
if (isFullScreen()) {
showNormal();
} else {
showFullScreen();
}
}