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();
ui->cmdExport->setEnabled(0);
plyrsList = QStringList();
fullscreenWidget = 0;
rqfullscreen = 0;
indexed = 0;
picArea = "";
picTitl = "";
@ -110,7 +112,7 @@ bool PictureDialog::eventFilter(QObject *obj, QEvent *ev)
break;
#endif
case Qt::Key_Enter: case Qt::Key_Return:
on_labPicture_mouseDoubleClicked();
on_labPicture_mouseDoubleClicked(Qt::LeftButton);
returnValue = true;
break;
}
@ -119,9 +121,20 @@ bool PictureDialog::eventFilter(QObject *obj, QEvent *ev)
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)
{
ev->accept();
QDialog::mousePressEvent(ev);
}
void PictureDialog::dialogNextPictureRequested()
@ -263,25 +276,42 @@ void PictureDialog::playerNameUpdated()
}
void PictureDialog::exportSnapmaticPicture()
{
if (rqfullscreen && fullscreenWidget != 0)
{
PictureExport::exportPicture(fullscreenWidget, smpic);
}
else
{
PictureExport::exportPicture(this, smpic);
}
}
void PictureDialog::copySnapmaticPicture()
{
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)
{
if (button == Qt::LeftButton)
{
QRect desktopRect = QApplication::desktop()->screenGeometry();
PictureWidget *pictureWidget = new PictureWidget(this);
pictureWidget->setWindowFlags(pictureWidget->windowFlags()^Qt::WindowContextHelpButtonHint);
pictureWidget->setWindowTitle(this->windowTitle());
pictureWidget->setStyleSheet("background-color: black;");
pictureWidget->setStyleSheet("QLabel#pictureLabel{background-color: black;}");
pictureWidget->setImage(snapmaticPicture, desktopRect);
pictureWidget->setModal(true);
fullscreenWidget = pictureWidget;
QObject::connect(this, SIGNAL(newPictureCommited(QImage)), pictureWidget, SLOT(setImage(QImage)));
QObject::connect(pictureWidget, SIGNAL(nextPictureRequested()), this, SLOT(dialogNextPictureRequested()));
QObject::connect(pictureWidget, SIGNAL(previousPictureRequested()), this, SLOT(dialogPreviousPictureRequested()));
@ -292,6 +322,12 @@ void PictureDialog::on_labPicture_mouseDoubleClicked()
delete pictureWidget;
}
}
void PictureDialog::on_labPicture_customContextMenuRequested(const QPoint &pos)
{
exportCustomContextMenuRequestedPrivate(ui->labPicture->mapToGlobal(pos), false);
}
bool PictureDialog::isIndexed()
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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