summary refs log tree commit diff
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-08-06 10:35:32 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-08-06 10:35:32 +0300
commit4fccc6270efca35f860fc39bc241cb0b0e032dff (patch)
treec6d55d6faa08f220a8cc5b20454de0be0128b842
parentThe emoji panel shouldn't steal focus from other windows (diff)
downloadnheko-4fccc6270efca35f860fc39bc241cb0b0e032dff.tar.xz
Fix full screen image viewer on macOS sierra
-rw-r--r--include/ImageOverlayDialog.h8
-rw-r--r--src/ImageOverlayDialog.cc36
2 files changed, 17 insertions, 27 deletions
diff --git a/include/ImageOverlayDialog.h b/include/ImageOverlayDialog.h
index 6763b9d1..287b2d1b 100644
--- a/include/ImageOverlayDialog.h
+++ b/include/ImageOverlayDialog.h
@@ -21,14 +21,12 @@
 #include <QMouseEvent>
 #include <QPixmap>
 
-class ImageOverlayDialog : public QDialog
+class ImageOverlayDialog : public QWidget
 {
 	Q_OBJECT
 public:
 	ImageOverlayDialog(QPixmap image, QWidget *parent = nullptr);
 
-	void reject() override;
-
 protected:
 	void mousePressEvent(QMouseEvent *event) override;
 	void paintEvent(QPaintEvent *event) override;
@@ -36,9 +34,6 @@ protected:
 signals:
 	void closing();
 
-private slots:
-	void closeDialog();
-
 private:
 	void scaleImage(int width, int height);
 
@@ -47,4 +42,5 @@ private:
 
 	QRect content_;
 	QRect close_button_;
+	QRect screen_;
 };
diff --git a/src/ImageOverlayDialog.cc b/src/ImageOverlayDialog.cc
index b23f2a34..786b011c 100644
--- a/src/ImageOverlayDialog.cc
+++ b/src/ImageOverlayDialog.cc
@@ -15,43 +15,37 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <QApplication>
 #include <QDebug>
+#include <QDesktopWidget>
 #include <QPainter>
+#include <QScreen>
 #include <QTimer>
 
 #include "ImageOverlayDialog.h"
 
 ImageOverlayDialog::ImageOverlayDialog(QPixmap image, QWidget *parent)
-    : QDialog{parent}
+    : QWidget{parent}
     , originalImage_{image}
 {
 	setMouseTracking(true);
-	setModal(false);
+	setParent(0);
 
 	setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
 
 	setAttribute(Qt::WA_NoSystemBackground, true);
 	setAttribute(Qt::WA_TranslucentBackground, true);
 	setAttribute(Qt::WA_DeleteOnClose, true);
-
 	setWindowState(Qt::WindowFullScreen);
 
-	connect(this, SIGNAL(closing()), this, SLOT(closeDialog()));
-}
+	screen_ = QApplication::desktop()->availableGeometry();
 
-void ImageOverlayDialog::reject()
-{
-	// needed on macOS to recover the main menu after the dialog is closed(!)
-	// also affects KDE/Plasma.  XXX: There may be a better way of resetting the
-	// window state than this...
-	setWindowState(Qt::WindowNoState);
+	move(QApplication::desktop()->mapToGlobal(screen_.topLeft()));
+	resize(screen_.size());
 
-	QDialog::reject();
-}
+	connect(this, SIGNAL(closing()), this, SLOT(close()));
 
-void ImageOverlayDialog::closeDialog()
-{
-	QTimer::singleShot(100, this, &ImageOverlayDialog::reject);
+	raise();
 }
 
 // TODO: Move this into Utils
@@ -87,15 +81,15 @@ void ImageOverlayDialog::paintEvent(QPaintEvent *event)
 	painter.setRenderHint(QPainter::Antialiasing);
 
 	// Full screen overlay.
-	painter.fillRect(rect(), QColor(55, 55, 55, 170));
+	painter.fillRect(QRect(0, 0, screen_.width(), screen_.height()), QColor(55, 55, 55, 170));
 
 	// Left and Right margins
-	int outer_margin = rect().width() * 0.12;
+	int outer_margin = screen_.width() * 0.12;
 	int buttonSize = 36;
 	int margin = outer_margin * 0.1;
 
-	int max_width = rect().width() - 2 * outer_margin;
-	int max_height = rect().height();
+	int max_width = screen_.width() - 2 * outer_margin;
+	int max_height = screen_.height();
 
 	scaleImage(max_width, max_height);
 
@@ -103,7 +97,7 @@ void ImageOverlayDialog::paintEvent(QPaintEvent *event)
 	int diff_y = max_height - image_.height();
 
 	content_ = QRect(outer_margin + diff_x / 2, diff_y / 2, image_.width(), image_.height());
-	close_button_ = QRect(rect().width() - margin - buttonSize, margin, buttonSize, buttonSize);
+	close_button_ = QRect(screen_.width() - margin - buttonSize, margin, buttonSize, buttonSize);
 
 	// Draw main content_.
 	painter.drawPixmap(content_, image_);