summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Nemeth <[email protected]>2018-02-09 18:51:14 +0100
committerHenrik Fehlauer <[email protected]>2018-02-09 18:54:40 +0100
commit4ab95e7ea4209299274f688022002d1e7262741a (patch)
tree8c8a524595c8b01dbe303685eac727196b9b6611
parentf8ab96be2d6194deff56f8bed92cb506062469ec (diff)
Let window size depend on the screenshot aspect ratio
Summary: Now the window width size changes with the aspect ratio of the captured image. Maximum width is 1000 pixels for this automatic resize. Test Plan: {F5697651} Reviewers: ngraham, #spectacle, rkflx Reviewed By: ngraham, #spectacle, rkflx Subscribers: rkflx, ngraham Tags: #spectacle Differential Revision: https://phabricator.kde.org/D10377
-rw-r--r--src/Gui/KSImageWidget.cpp2
-rw-r--r--src/Gui/KSImageWidget.h5
-rw-r--r--src/Gui/KSMainWindow.cpp24
-rw-r--r--src/Gui/KSMainWindow.h1
-rw-r--r--src/Gui/KSWidget.cpp22
-rw-r--r--src/Gui/KSWidget.h6
6 files changed, 53 insertions, 7 deletions
diff --git a/src/Gui/KSImageWidget.cpp b/src/Gui/KSImageWidget.cpp
index 7e9ce07..a627f5a 100644
--- a/src/Gui/KSImageWidget.cpp
+++ b/src/Gui/KSImageWidget.cpp
@@ -25,7 +25,7 @@ KSImageWidget::KSImageWidget(QWidget *parent):
{
mDSEffect = new QGraphicsDropShadowEffect(this);
- mDSEffect->setBlurRadius(5);
+ mDSEffect->setBlurRadius(SpectacleImage::SHADOW_RADIUS);
mDSEffect->setOffset(0);
mDSEffect->setColor(QColor(Qt::black));
diff --git a/src/Gui/KSImageWidget.h b/src/Gui/KSImageWidget.h
index 0433698..d579f8d 100644
--- a/src/Gui/KSImageWidget.h
+++ b/src/Gui/KSImageWidget.h
@@ -31,10 +31,15 @@
#include <KLocalizedString>
+namespace SpectacleImage {
+ static const int SHADOW_RADIUS = 5;
+}
+
class KSImageWidget : public QLabel
{
Q_OBJECT
+
public:
explicit KSImageWidget(QWidget *parent = 0);
diff --git a/src/Gui/KSMainWindow.cpp b/src/Gui/KSMainWindow.cpp
index 60dbab7..e491cb4 100644
--- a/src/Gui/KSMainWindow.cpp
+++ b/src/Gui/KSMainWindow.cpp
@@ -46,6 +46,10 @@
#include "ExportManager.h"
#include "SpectacleConfig.h"
+static const int DEFAULT_WINDOW_HEIGHT = 420;
+static const int DEFAULT_WINDOW_WIDTH = 840;
+static const int MAXIMUM_WINDOW_WIDTH = 1000;
+
KSMainWindow::KSMainWindow(bool onClickAvailable, QWidget *parent) :
QDialog(parent),
mKSWidget(new KSWidget),
@@ -186,12 +190,28 @@ void KSMainWindow::init()
if (!mOnClickAvailable) {
mKSWidget->disableOnClick();
}
- resize(QSize(840, 420).expandedTo(minimumSize()));
+ resize(QSize(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT).expandedTo(minimumSize()));
// done with the init
}
+int KSMainWindow::windowWidth(const QPixmap &pixmap) const
+{
+ // Calculates what the width of the window should be for the captured image to perfectly fit
+ // the area reserved for the image, with the height already set.
+
+ const float pixmapAspectRatio = (float)pixmap.width() / pixmap.height();
+ const int imageHeight = mKSWidget->height() - 2 * layout()->spacing();
+ const int imageWidth = pixmapAspectRatio * imageHeight;
+
+ int alignedWindowWidth = qMin(mKSWidget->imagePaddingWidth() + imageWidth, MAXIMUM_WINDOW_WIDTH);
+ alignedWindowWidth += layout()->contentsMargins().left() + layout()->contentsMargins().right();
+ alignedWindowWidth += 2; // margins is removing 1 - 1 pixel for some reason
+
+ return alignedWindowWidth;
+}
+
void KSMainWindow::buildSaveMenu()
{
// first clear the menu
@@ -260,6 +280,8 @@ void KSMainWindow::setScreenshotAndShow(const QPixmap &pixmap)
setWindowModified(true);
show();
+
+ resize(QSize(windowWidth(pixmap), DEFAULT_WINDOW_HEIGHT));
}
void KSMainWindow::showPrintDialog()
diff --git a/src/Gui/KSMainWindow.h b/src/Gui/KSMainWindow.h
index 350e572..ab78f31 100644
--- a/src/Gui/KSMainWindow.h
+++ b/src/Gui/KSMainWindow.h
@@ -53,6 +53,7 @@ class KSMainWindow : public QDialog
void save();
void saveAs();
void saveAndExit();
+ int windowWidth(const QPixmap &pixmap) const;
public slots:
diff --git a/src/Gui/KSWidget.cpp b/src/Gui/KSWidget.cpp
index 8dceab2..28612ec 100644
--- a/src/Gui/KSWidget.cpp
+++ b/src/Gui/KSWidget.cpp
@@ -142,13 +142,13 @@ KSWidget::KSWidget(QWidget *parent) :
mRightLayout->addLayout(mContentOptionsForm);
mRightLayout->addStretch(10);
mRightLayout->addWidget(mTakeScreenshotButton, 1, Qt::AlignHCenter);
- mRightLayout->setContentsMargins(20, 0, 0, 10);
+ mRightLayout->setContentsMargins(10, 0, 0, 10);
mMainLayout = new QGridLayout(this);
mMainLayout->addWidget(mImageWidget, 0, 0, 1, 1);
mMainLayout->addLayout(mRightLayout, 0, 1, 1, 1);
- mMainLayout->setColumnMinimumWidth(0, 400);
- mMainLayout->setColumnMinimumWidth(1, 400);
+ mMainLayout->setColumnMinimumWidth(0, 320);
+ mMainLayout->setColumnMinimumWidth(1, 320);
// and read in the saved checkbox states and capture mode indices
@@ -162,6 +162,22 @@ KSWidget::KSWidget(QWidget *parent) :
// done
}
+int KSWidget::imagePaddingWidth() const
+{
+ int rightLayoutLeft = 0;
+ int rightLayoutRight = 0;
+ int mainLayoutRight = 0;
+
+ mRightLayout->getContentsMargins(&rightLayoutLeft, nullptr, &rightLayoutRight, nullptr);
+ mMainLayout->getContentsMargins(nullptr, nullptr, &mainLayoutRight, nullptr);
+
+ int paddingWidth = (rightLayoutLeft + rightLayoutRight + mainLayoutRight);
+ paddingWidth += mRightLayout->contentsRect().width();
+ paddingWidth += 2 * SpectacleImage::SHADOW_RADIUS; // image drop shadow
+
+ return paddingWidth;
+}
+
// public slots
void KSWidget::setScreenshotPixmap(const QPixmap &pixmap)
diff --git a/src/Gui/KSWidget.h b/src/Gui/KSWidget.h
index 9a73e79..11998af 100644
--- a/src/Gui/KSWidget.h
+++ b/src/Gui/KSWidget.h
@@ -42,9 +42,11 @@ class KSWidget : public QWidget
Q_OBJECT
public:
-
+
explicit KSWidget(QWidget *parent = 0);
+ int imagePaddingWidth() const;
+
signals:
void dragInitiated();
@@ -62,7 +64,7 @@ class KSWidget : public QWidget
void captureModeChanged(int index);
private:
-
+
QGridLayout *mMainLayout;
QHBoxLayout *mDelayLayout;
QVBoxLayout *mRightLayout;