pictureDialog context menu in normal+fullscreen

This commit is contained in:
Rafael 2016-04-24 12:47:14 +02:00
parent 787bb81fda
commit d42f263f4e
7 changed files with 88 additions and 28 deletions

View file

@ -52,6 +52,8 @@ PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) :
jsonDrawString = ui->labJSON->text(); jsonDrawString = ui->labJSON->text();
ui->cmdExport->setEnabled(0); ui->cmdExport->setEnabled(0);
plyrsList = QStringList(); plyrsList = QStringList();
fullscreenWidget = 0;
rqfullscreen = 0;
indexed = 0; indexed = 0;
picArea = ""; picArea = "";
picTitl = ""; picTitl = "";
@ -110,7 +112,7 @@ bool PictureDialog::eventFilter(QObject *obj, QEvent *ev)
break; break;
#endif #endif
case Qt::Key_Enter: case Qt::Key_Return: case Qt::Key_Enter: case Qt::Key_Return:
on_labPicture_mouseDoubleClicked(); on_labPicture_mouseDoubleClicked(Qt::LeftButton);
returnValue = true; returnValue = true;
break; break;
} }
@ -119,9 +121,20 @@ bool PictureDialog::eventFilter(QObject *obj, QEvent *ev)
return returnValue; return returnValue;
} }
void PictureDialog::exportCustomContextMenuRequestedPrivate(const QPoint &pos, bool fullscreen)
{
rqfullscreen = fullscreen;
exportMenu->exec(pos);
}
void PictureDialog::exportCustomContextMenuRequested(const QPoint &pos)
{
exportCustomContextMenuRequestedPrivate(pos, true);
}
void PictureDialog::mousePressEvent(QMouseEvent *ev) void PictureDialog::mousePressEvent(QMouseEvent *ev)
{ {
ev->accept(); QDialog::mousePressEvent(ev);
} }
void PictureDialog::dialogNextPictureRequested() void PictureDialog::dialogNextPictureRequested()
@ -264,33 +277,56 @@ void PictureDialog::playerNameUpdated()
void PictureDialog::exportSnapmaticPicture() void PictureDialog::exportSnapmaticPicture()
{ {
PictureExport::exportPicture(this, smpic); if (rqfullscreen && fullscreenWidget != 0)
{
PictureExport::exportPicture(fullscreenWidget, smpic);
}
else
{
PictureExport::exportPicture(this, smpic);
}
} }
void PictureDialog::copySnapmaticPicture() void PictureDialog::copySnapmaticPicture()
{ {
PictureCopy::copyPicture(this, picPath); if (rqfullscreen && fullscreenWidget != 0)
{
PictureCopy::copyPicture(fullscreenWidget, picPath);
}
else
{
PictureCopy::copyPicture(this, picPath);
}
} }
void PictureDialog::on_labPicture_mouseDoubleClicked() void PictureDialog::on_labPicture_mouseDoubleClicked(Qt::MouseButton button)
{ {
QRect desktopRect = QApplication::desktop()->screenGeometry(); if (button == Qt::LeftButton)
PictureWidget *pictureWidget = new PictureWidget(this); {
pictureWidget->setWindowFlags(pictureWidget->windowFlags()^Qt::WindowContextHelpButtonHint); QRect desktopRect = QApplication::desktop()->screenGeometry();
pictureWidget->setWindowTitle(this->windowTitle()); PictureWidget *pictureWidget = new PictureWidget(this);
pictureWidget->setStyleSheet("background-color: black;"); pictureWidget->setWindowFlags(pictureWidget->windowFlags()^Qt::WindowContextHelpButtonHint);
pictureWidget->setImage(snapmaticPicture, desktopRect); pictureWidget->setWindowTitle(this->windowTitle());
pictureWidget->setModal(true); pictureWidget->setStyleSheet("QLabel#pictureLabel{background-color: black;}");
pictureWidget->setImage(snapmaticPicture, desktopRect);
pictureWidget->setModal(true);
QObject::connect(this, SIGNAL(newPictureCommited(QImage)), pictureWidget, SLOT(setImage(QImage))); fullscreenWidget = pictureWidget;
QObject::connect(pictureWidget, SIGNAL(nextPictureRequested()), this, SLOT(dialogNextPictureRequested())); QObject::connect(this, SIGNAL(newPictureCommited(QImage)), pictureWidget, SLOT(setImage(QImage)));
QObject::connect(pictureWidget, SIGNAL(previousPictureRequested()), this, SLOT(dialogPreviousPictureRequested())); QObject::connect(pictureWidget, SIGNAL(nextPictureRequested()), this, SLOT(dialogNextPictureRequested()));
QObject::connect(pictureWidget, SIGNAL(previousPictureRequested()), this, SLOT(dialogPreviousPictureRequested()));
pictureWidget->showFullScreen(); pictureWidget->showFullScreen();
pictureWidget->setFocus(); pictureWidget->setFocus();
pictureWidget->exec(); pictureWidget->exec();
delete pictureWidget; delete pictureWidget;
}
}
void PictureDialog::on_labPicture_customContextMenuRequested(const QPoint &pos)
{
exportCustomContextMenuRequestedPrivate(ui->labPicture->mapToGlobal(pos), false);
} }
bool PictureDialog::isIndexed() bool PictureDialog::isIndexed()

View file

@ -50,11 +50,14 @@ public slots:
void playerNameUpdated(); void playerNameUpdated();
void dialogNextPictureRequested(); void dialogNextPictureRequested();
void dialogPreviousPictureRequested(); void dialogPreviousPictureRequested();
void exportCustomContextMenuRequested(const QPoint &pos);
private slots: private slots:
void copySnapmaticPicture(); void copySnapmaticPicture();
void exportSnapmaticPicture(); void exportSnapmaticPicture();
void on_labPicture_mouseDoubleClicked(); void on_labPicture_mouseDoubleClicked(Qt::MouseButton button);
void on_labPicture_customContextMenuRequested(const QPoint &pos);
void exportCustomContextMenuRequestedPrivate(const QPoint &pos, bool fullscreen);
signals: signals:
void nextPictureRequested(); void nextPictureRequested();
@ -70,6 +73,7 @@ private:
Ui::PictureDialog *ui; Ui::PictureDialog *ui;
QMap<QString, QString> globalMap; QMap<QString, QString> globalMap;
SnapmaticPicture *smpic; SnapmaticPicture *smpic;
QWidget *fullscreenWidget;
QImage snapmaticPicture; QImage snapmaticPicture;
QString jsonDrawString; QString jsonDrawString;
QString windowTitleStr; QString windowTitleStr;
@ -82,6 +86,7 @@ private:
QString locX; QString locX;
QString locY; QString locY;
QString locZ; QString locZ;
bool rqfullscreen;
bool indexed; bool indexed;
int index; int index;
QMenu *exportMenu; QMenu *exportMenu;

View file

@ -34,6 +34,9 @@
<verstretch>1</verstretch> <verstretch>1</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>

View file

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include "PictureDialog.h"
#include "PictureWidget.h" #include "PictureWidget.h"
#include "UiModLabel.h" #include "UiModLabel.h"
#include <QHBoxLayout> #include <QHBoxLayout>
@ -32,11 +33,14 @@ PictureWidget::PictureWidget(QWidget *parent) : QDialog(parent)
widgetLayout->setContentsMargins(0, 0, 0, 0); widgetLayout->setContentsMargins(0, 0, 0, 0);
pictureLabel = new UiModLabel(this); pictureLabel = new UiModLabel(this);
pictureLabel->setObjectName("pictureLabel");
pictureLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); pictureLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
pictureLabel->setContextMenuPolicy(Qt::CustomContextMenu);
pictureLabel->setAlignment(Qt::AlignCenter); pictureLabel->setAlignment(Qt::AlignCenter);
widgetLayout->addWidget(pictureLabel); widgetLayout->addWidget(pictureLabel);
QObject::connect(pictureLabel, SIGNAL(mouseDoubleClicked()), this, SLOT(close())); QObject::connect(pictureLabel, SIGNAL(mouseDoubleClicked(Qt::MouseButton)), this, SLOT(pictureDoubleClicked(Qt::MouseButton)));
QObject::connect(pictureLabel, SIGNAL(customContextMenuRequested(QPoint)), parent, SLOT(exportCustomContextMenuRequested(QPoint)));
setLayout(widgetLayout); setLayout(widgetLayout);
} }
@ -68,6 +72,14 @@ bool PictureWidget::eventFilter(QObject *obj, QEvent *ev)
return false; return false;
} }
void PictureWidget::pictureDoubleClicked(Qt::MouseButton button)
{
if (button == Qt::LeftButton)
{
close();
}
}
void PictureWidget::setImage(QImage image, QRect rec) void PictureWidget::setImage(QImage image, QRect rec)
{ {
pictureLabel->setPixmap(QPixmap::fromImage(image.scaled(rec.width(), rec.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation))); pictureLabel->setPixmap(QPixmap::fromImage(image.scaled(rec.width(), rec.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation)));

View file

@ -43,6 +43,9 @@ private:
QHBoxLayout *widgetLayout; QHBoxLayout *widgetLayout;
UiModLabel *pictureLabel; UiModLabel *pictureLabel;
private slots:
void pictureDoubleClicked(Qt::MouseButton button);
signals: signals:
void nextPictureRequested(); void nextPictureRequested();
void previousPictureRequested(); void previousPictureRequested();

View file

@ -17,6 +17,7 @@
*****************************************************************************/ *****************************************************************************/
#include "UiModLabel.h" #include "UiModLabel.h"
#include <QMouseEvent>
UiModLabel::UiModLabel(const QString &text, QWidget *parent) : QLabel(parent) UiModLabel::UiModLabel(const QString &text, QWidget *parent) : QLabel(parent)
{ {
@ -45,17 +46,17 @@ void UiModLabel::mouseMoveEvent(QMouseEvent *ev)
void UiModLabel::mousePressEvent(QMouseEvent *ev) void UiModLabel::mousePressEvent(QMouseEvent *ev)
{ {
QLabel::mousePressEvent(ev); QLabel::mousePressEvent(ev);
emit mousePressed(); emit mousePressed(ev->button());
} }
void UiModLabel::mouseReleaseEvent(QMouseEvent *ev) void UiModLabel::mouseReleaseEvent(QMouseEvent *ev)
{ {
QLabel::mouseReleaseEvent(ev); QLabel::mouseReleaseEvent(ev);
emit mouseReleased(); emit mouseReleased(ev->button());
} }
void UiModLabel::mouseDoubleClickEvent(QMouseEvent *ev) void UiModLabel::mouseDoubleClickEvent(QMouseEvent *ev)
{ {
QLabel::mouseDoubleClickEvent(ev); QLabel::mouseDoubleClickEvent(ev);
emit mouseDoubleClicked(); emit mouseDoubleClicked(ev->button());
} }

View file

@ -20,8 +20,8 @@
#define UIMODLABEL_H #define UIMODLABEL_H
#include <QWidget> #include <QWidget>
#include <QLabel>
#include <QString> #include <QString>
#include <QLabel>
class UiModLabel : public QLabel class UiModLabel : public QLabel
{ {
@ -40,9 +40,9 @@ protected:
signals: signals:
void mouseMoved(); void mouseMoved();
void mousePressed(); void mousePressed(Qt::MouseButton button);
void mouseReleased(); void mouseReleased(Qt::MouseButton button);
void mouseDoubleClicked(); void mouseDoubleClicked(Qt::MouseButton button);
}; };
#endif // UIMODLABEL_H #endif // UIMODLABEL_H