Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
14 KB
Referenced Files
None
Subscribers
None
diff --git a/dialogs/previewdialog.cpp b/dialogs/previewdialog.cpp
index e774962..a80c6a5 100644
--- a/dialogs/previewdialog.cpp
+++ b/dialogs/previewdialog.cpp
@@ -1,367 +1,363 @@
/*
* Copyright (C) 2011 Christian Kaiser
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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 this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "previewdialog.h"
#include "screenshotdialog.h"
#include "../tools/screenshot.h"
#include "../tools/screenshotmanager.h"
#include "../tools/os.h"
#include <QApplication>
#include <QObject>
#include <QList>
#include <QHBoxLayout>
#include <QIcon>
#include <QPushButton>
#include <QPalette>
#include <QDesktopWidget>
#include <QGraphicsDropShadowEffect>
#include <QLabel>
#include <QStackedLayout>
#include <QSettings>
#include <QToolButton>
#include <QMenu>
#include <QDebug>
PreviewDialog::PreviewDialog(QWidget *parent) :
QDialog(parent), mAutoclose(0)
{
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
os::aeroGlass(this);
setWindowTitle("Screenshot Preview");
QSettings *settings = ScreenshotManager::instance()->settings();
mSize = settings->value("options/previewSize", 300).toInt();
mPosition = settings->value("options/previewPosition", 3).toInt();
if (settings->value("options/previewAutoclose", false).toBool()) {
mAutoclose = settings->value("options/previewAutocloseTime").toInt();
mAutocloseReset = mAutoclose;
mAutocloseAction = settings->value("options/previewAutocloseAction").toInt();
}
QHBoxLayout *l = new QHBoxLayout;
mStack = new QStackedLayout;
connect(mStack, SIGNAL(currentChanged(int)), this, SLOT(indexChanged(int)));
mPrevButton = new QPushButton(QIcon(":/icons/arrow-left"), "", this);
connect(mPrevButton, SIGNAL(clicked()), this, SLOT(previous()));
mNextButton = new QPushButton(QIcon(":/icons/arrow-right"), "", this);
connect(mNextButton, SIGNAL(clicked()), this, SLOT(next()));
mPrevButton->setCursor(Qt::PointingHandCursor);
mPrevButton->setFlat(true);
mPrevButton->setGraphicsEffect(os::shadow());
mPrevButton->setIconSize(QSize(24, 24));
mPrevButton->setVisible(false);
mNextButton->setCursor(Qt::PointingHandCursor);
mNextButton->setFlat(true);
mNextButton->setGraphicsEffect(os::shadow());
mNextButton->setIconSize(QSize(24, 24));
mNextButton->setVisible(false);
l->addWidget(mPrevButton);
l->addLayout(mStack);
l->addWidget(mNextButton);
l->setMargin(0);
l->setContentsMargins(6, 6, 6, 6);
mStack->setMargin(0);
setMaximumHeight(mSize);
setLayout(l);
if (mAutoclose) {
startTimer(1000);
}
}
void PreviewDialog::add(Screenshot *screenshot)
{
if (!isVisible()) {
show();
}
if (mAutoclose) {
mAutoclose = mAutocloseReset;
}
QLabel *label = new QLabel(this);
- label->installEventFilter(this);
label->setGraphicsEffect(os::shadow());
bool small = false;
connect(label, SIGNAL(destroyed()), screenshot, SLOT(discard()));
QSize size = screenshot->pixmap().size();
if (size.width() > mSize || size.height() > mSize) {
size.scale(mSize, mSize, Qt::KeepAspectRatio);
}
else {
small = true;
}
QPixmap thumbnail = screenshot->pixmap().scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
label->setPixmap(thumbnail);
thumbnail = QPixmap();
label->setAlignment(Qt::AlignCenter);
- if (size.height() < 80) {
- label->setMinimumHeight(80);
+ if (size.height() < 120) {
+ label->setMinimumHeight(120);
}
- if (size.width() < 80) {
- label->setMinimumWidth(80);
+ if (size.width() < 140) {
+ label->setMinimumWidth(140);
}
label->resize(size);
QToolButton *confirmPushButton = new QToolButton(label);
QPushButton *discardPushButton = new QPushButton(QIcon(":/icons/no") , "", label);
QPushButton *enlargePushButton = new QPushButton(QIcon(":/icons/zoom.in"), "", label);
confirmPushButton->setIcon(QIcon(":/icons/yes"));
- //confirmPushButton->setStyleSheet("QToolButton { padding: 4px 10px; } QToolButton::menu-arrow { background: transparent; }");
confirmPushButton->setIconSize(QSize(24, 24));
confirmPushButton->setCursor(Qt::PointingHandCursor);
confirmPushButton->setGraphicsEffect(os::shadow());
- QMenu *confirmMenu = new QMenu(confirmPushButton);
- confirmMenu->setObjectName("confirmMenu");
+ if (!ScreenshotManager::instance()->settings()->value("options/uploadAuto").toBool()) {
+ QMenu *confirmMenu = new QMenu(confirmPushButton);
+ confirmMenu->setObjectName("confirmMenu");
- QAction *uploadAction = new QAction(QIcon(":/icons/imgur"), tr("Upload"), confirmMenu);
+ QAction *uploadAction = new QAction(QIcon(":/icons/imgur"), tr("Upload"), confirmPushButton);
+ connect(uploadAction, SIGNAL(triggered()), screenshot, SLOT(confirm()));
+ connect(uploadAction, SIGNAL(triggered()), parent(), SLOT(uploadLast()));
+ connect(uploadAction, SIGNAL(triggered()), this, SLOT(closePreview()));
+
+ confirmMenu->addAction(uploadAction);
+ confirmPushButton->setMenu(confirmMenu);
+ confirmPushButton->setPopupMode(QToolButton::MenuButtonPopup);
+ }
- confirmMenu->addAction(uploadAction);
- confirmPushButton->setMenu(confirmMenu);
- confirmPushButton->setPopupMode(QToolButton::MenuButtonPopup);
confirmPushButton->setVisible(false);
discardPushButton->setIconSize(QSize(24, 24));
discardPushButton->setCursor(Qt::PointingHandCursor);
discardPushButton->setGraphicsEffect(os::shadow());
discardPushButton->setVisible(false);
enlargePushButton->setIconSize(QSize(22, 22));
enlargePushButton->setCursor(Qt::PointingHandCursor);
enlargePushButton->setGraphicsEffect(os::shadow());
enlargePushButton->setVisible(false);
enlargePushButton->setDisabled(small);
connect(this, SIGNAL(acceptAll()), confirmPushButton, SLOT(click()));
connect(this, SIGNAL(rejectAll()), discardPushButton, SLOT(click()));
connect(confirmPushButton, SIGNAL(clicked()), screenshot, SLOT(confirm()));
connect(confirmPushButton, SIGNAL(clicked()), this, SLOT(closePreview()));
- connect(uploadAction, SIGNAL(triggered()), screenshot, SLOT(confirm()));
- connect(uploadAction, SIGNAL(triggered()), parent(), SLOT(uploadLast()));
- connect(uploadAction, SIGNAL(triggered()), this, SLOT(closePreview()));
-
connect(discardPushButton, SIGNAL(clicked()), screenshot, SLOT(discard()));
connect(discardPushButton, SIGNAL(clicked()), this, SLOT(closePreview()));
connect(enlargePushButton, SIGNAL(clicked()), this, SLOT(enlargePreview()));
QHBoxLayout *wlayout = new QHBoxLayout;
wlayout->addWidget(confirmPushButton);
wlayout->addStretch();
wlayout->addWidget(enlargePushButton);
wlayout->addStretch();
wlayout->addWidget(discardPushButton);
wlayout->setMargin(0);
QVBoxLayout *wl = new QVBoxLayout;
wl->addStretch();
wl->addLayout(wlayout);
wl->setMargin(0);
label->setLayout(wl);
mStack->addWidget(label);
mStack->setCurrentIndex(mStack->count()-1);
mNextButton->setEnabled(false);
if (mStack->count() >= 2 && !mNextButton->isVisible()) {
mNextButton->setVisible(true);
mPrevButton->setVisible(true);
}
relocate();
}
int PreviewDialog::count() const
{
return mStack->count();
}
void PreviewDialog::relocate()
{
updateGeometry();
resize(minimumSizeHint());
QPoint where;
switch (mPosition)
{
case 0:
where = QApplication::desktop()->availableGeometry(this).topLeft();
break;
case 1:
where = QApplication::desktop()->availableGeometry(this).topRight();
where.setX(where.x() - frameGeometry().width());
break;
case 2:
where = QApplication::desktop()->availableGeometry(this).bottomLeft();
where.setY(where.y() - frameGeometry().height());
break;
case 3:
default:
where = QApplication::desktop()->availableGeometry(this).bottomRight();
where.setX(where.x() - frameGeometry().width());
where.setY(where.y() - frameGeometry().height());
break;
}
move(where);
}
void PreviewDialog::closePreview()
{
- QWidget *container = qobject_cast<QWidget*>(sender()->parent());
- mStack->removeWidget(container);
- container->deleteLater();
+ QWidget *widget = mStack->currentWidget();
+ mStack->removeWidget(widget);
+ widget->deleteLater();
if (mStack->count() == 0) {
close();
}
else {
relocate();
}
}
void PreviewDialog::indexChanged(int i)
{
if (i == mStack->count()-1) {
mNextButton->setEnabled(false);
mPrevButton->setEnabled(true);
}
if (i == 0 && mStack->count() > 1) {
mNextButton->setEnabled(true);
mPrevButton->setEnabled(false);
}
if (i != 0 && i != mStack->count()-1) {
mNextButton->setEnabled(true);
mPrevButton->setEnabled(true);
}
if (mStack->count() < 2) {
mNextButton->setEnabled(false);
mPrevButton->setEnabled(false);
}
if (mStack->widget(i)) {
mStack->widget(i)->setFocus();
}
}
void PreviewDialog::previous()
{
mStack->setCurrentIndex(mStack->currentIndex()-1);
relocate();
+ QApplication::sendEvent(this, new QEvent(QEvent::Enter)); // Ensures the buttons are visible.
}
void PreviewDialog::next()
{
mStack->setCurrentIndex(mStack->currentIndex()+1);
relocate();
+ QApplication::sendEvent(this, new QEvent(QEvent::Enter));
}
void PreviewDialog::enlargePreview()
{
Screenshot *screenshot = qobject_cast<Screenshot*>(ScreenshotManager::instance()->children().at(mStack->currentIndex()));
if (screenshot) {
new ScreenshotDialog(screenshot, this);
}
}
-void PreviewDialog::closeEvent(QCloseEvent *event)
+bool PreviewDialog::event(QEvent *event)
{
- Q_UNUSED(event)
- deleteLater();
-}
+ if ((event->type() == QEvent::Enter || event->type() == QEvent::Leave)
+ && mStack->currentWidget())
+ {
+ foreach (QObject *child, mStack->currentWidget()->children()) {
+ QWidget *widget = qobject_cast<QWidget*>(child);
-void PreviewDialog::mouseDoubleClickEvent(QMouseEvent *event)
-{
- Q_UNUSED(event)
- enlargePreview();
+ if (widget) {
+ // Lets avoid disappearing buttons and bail if the menu is open.
+ QMenu *confirmMenu = widget->findChild<QMenu*>("confirmMenu");
+ if (confirmMenu && confirmMenu->isVisible())
+ return false;
+
+ widget->setVisible((event->type() == QEvent::Enter));
+ }
+ }
+ }
+ else if (event->type() == QEvent::Close) {
+ deleteLater();
+ }
+ else if (event->type() == QEvent::MouseButtonDblClick) {
+ enlargePreview();
+ }
+
+ return QDialog::event(event);
}
void PreviewDialog::timerEvent(QTimerEvent *event)
{
if (mAutoclose == 0) {
if (mAutocloseAction == 0) {
emit acceptAll();
}
else {
emit rejectAll();
}
}
else if (mAutoclose < 0) {
killTimer(event->timerId());
}
else {
setWindowTitle(tr("Preview: Closing in %1").arg(mAutoclose));
mAutoclose--;
}
}
-
-bool PreviewDialog::eventFilter(QObject *object, QEvent *event)
-{
- if (event->type() != QEvent::Enter && event->type() != QEvent::Leave) {
- return false;
- }
-
- foreach (QObject *child, object->children()) {
- QWidget *w = qobject_cast<QWidget*>(child);
-
- if (w) {
- // Lets avoid disappearing buttons and bail if the menu is open.
- QMenu *confirmMenu = w->findChild<QMenu*>("confirmMenu");
- if (confirmMenu && confirmMenu->isVisible())
- return false;
-
- w->setVisible((event->type() == QEvent::Enter));
- }
- }
-
- return true;
-}
diff --git a/dialogs/previewdialog.h b/dialogs/previewdialog.h
index 2500fa0..fe32e8c 100644
--- a/dialogs/previewdialog.h
+++ b/dialogs/previewdialog.h
@@ -1,74 +1,72 @@
/*
* Copyright (C) 2011 Christian Kaiser
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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 this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef PREVIEWDIALOG_H
#define PREVIEWDIALOG_H
#include <QDialog>
class Screenshot;
class QStackedLayout;
class QPushButton;
class PreviewDialog : public QDialog
{
Q_OBJECT
public:
PreviewDialog(QWidget *parent);
void add(Screenshot* screenshot);
int count() const;
static PreviewDialog *instance();
static bool isActive();
public slots:
void setWidth(int w) { resize(w, height()); }
void setHeight(int h) { resize(width(), h); }
signals:
void acceptAll();
void rejectAll();
private slots:
void closePreview();
void relocate();
void previous();
void next();
void indexChanged(int i);
void enlargePreview();
protected:
- void closeEvent(QCloseEvent* event);
- void mouseDoubleClickEvent(QMouseEvent *event);
void timerEvent(QTimerEvent *event);
- bool eventFilter(QObject *object, QEvent *event);
+ bool event(QEvent *event);
private:
static PreviewDialog* mInstance;
int mSize;
int mPosition; //0: top left, 1: top right, 2: bottom left, 3: bottom rigth (default)
int mAutoclose;
int mAutocloseReset;
int mAutocloseAction;
QStackedLayout* mStack;
QPushButton* mNextButton;
QPushButton* mPrevButton;
};
#endif // PREVIEWDIALOG_H

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jun 17, 9:22 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70546
Default Alt Text
(14 KB)

Event Timeline