Initial work towards better dpi support

This commit is contained in:
lupoDharkael
2018-01-17 23:43:22 +01:00
parent c8d4f613ff
commit 2c1080bfaa
11 changed files with 62 additions and 46 deletions

View File

@@ -23,22 +23,18 @@
// ButtonHandler is a habdler for every active button. It makes easier to
// manipulate the buttons as a unit.
namespace {
const int SEPARATION = 6;
}
ButtonHandler::ButtonHandler(const QVector<CaptureButton*> &v,
const QRect &limits, QObject *parent) :
QObject(parent), m_limits(limits)
{
setButtons(v);
updateScreenRegions();
init();
}
ButtonHandler::ButtonHandler(const QRect &limits, QObject *parent) :
QObject(parent), m_limits(limits)
{
updateScreenRegions();
init();
}
void ButtonHandler::hide() {
@@ -98,8 +94,8 @@ void ButtonHandler::updatePosition(const QRect &selection) {
break; // the while
}
// Number of buttons per row column
int buttonsPerRow = (m_selection.width() + SEPARATION) / (m_buttonExtendedSize);
int buttonsPerCol = (m_selection.height() + SEPARATION) / (m_buttonExtendedSize);
int buttonsPerRow = (m_selection.width() + m_separator) / (m_buttonExtendedSize);
int buttonsPerCol = (m_selection.height() + m_separator) / (m_buttonExtendedSize);
// Buttons to be placed in the corners
int extraButtons = (vecLength - elemIndicator) -
(buttonsPerRow + buttonsPerCol) * 2;
@@ -120,7 +116,7 @@ void ButtonHandler::updatePosition(const QRect &selection) {
// Don't add more than we have
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
QPoint center = QPoint(m_selection.center().x(),
m_selection.bottom() + SEPARATION);
m_selection.bottom() + m_separator);
if (addCounter > buttonsPerRow) {
adjustHorizontalCenter(center);
}
@@ -133,7 +129,7 @@ void ButtonHandler::updatePosition(const QRect &selection) {
int addCounter = buttonsPerCol;
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
QPoint center = QPoint(m_selection.right() + SEPARATION,
QPoint center = QPoint(m_selection.right() + m_separator,
m_selection.center().y());
QVector<QPoint> positions = verticalPoints(center, addCounter, false);
moveButtonsToPoints(positions, elemIndicator);
@@ -179,7 +175,7 @@ QVector<QPoint> ButtonHandler::horizontalPoints(
// Distance from the center to start adding buttons
int shift = 0;
if (elements % 2 == 0) {
shift = m_buttonExtendedSize * (elements / 2) - (SEPARATION / 2);
shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2);
} else {
shift = m_buttonExtendedSize * ((elements-1) / 2) + m_buttonBaseSize / 2;
}
@@ -205,7 +201,7 @@ QVector<QPoint> ButtonHandler::verticalPoints(
// Distance from the center to start adding buttons
int shift = 0;
if (elements % 2 == 0) {
shift = m_buttonExtendedSize * (elements / 2) - (SEPARATION / 2);
shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2);
} else {
shift = m_buttonExtendedSize * ((elements-1) / 2) + m_buttonBaseSize / 2;
}
@@ -221,12 +217,17 @@ QVector<QPoint> ButtonHandler::verticalPoints(
return res;
}
void ButtonHandler::init() {
updateScreenRegions();
m_separator = CaptureButton::buttonBaseSize() / 4;
}
void ButtonHandler::resetRegionTrack() {
m_buttonsAreInside = false;
}
void ButtonHandler::updateBlockedSides() {
const int EXTENSION = SEPARATION * 2 + m_buttonBaseSize;
const int EXTENSION = m_separator * 2 + m_buttonBaseSize;
// Right
QPoint pointA(m_selection.right() + EXTENSION,
m_selection.bottom());
@@ -284,10 +285,10 @@ void ButtonHandler::positionButtonsInside(int index) {
// The main screen has priority as the reference when its x,y botton
// left corner values are lower than the ones of the selection.
QRect mainArea = QGuiApplication::primaryScreen()->geometry();
int xPos = m_selection.left() + SEPARATION;
int xPos = m_selection.left() + m_separator;
int yPos = m_selection.bottom() - m_buttonExtendedSize;
if (m_selection.left() < mainArea.left()) {
xPos = mainArea.left() + SEPARATION;
xPos = mainArea.left() + m_separator;
}
if (m_selection.bottom() > mainArea.bottom()) {
yPos = mainArea.bottom() - m_buttonExtendedSize;
@@ -297,7 +298,7 @@ void ButtonHandler::positionButtonsInside(int index) {
button = m_vectorButtons[index];
button->move(xPos, yPos);
if (button->pos().x() + m_buttonExtendedSize > mainArea.right()) {
xPos = m_selection.left() + SEPARATION;
xPos = m_selection.left() + m_separator;
yPos -= (m_buttonExtendedSize);
}
xPos += (m_buttonExtendedSize);
@@ -350,8 +351,8 @@ void ButtonHandler::setButtons(const QVector<CaptureButton *> v) {
for (CaptureButton *b: m_vectorButtons)
delete(b);
m_vectorButtons = v;
m_buttonBaseSize = v[0]->buttonBaseSize();
m_buttonExtendedSize = m_buttonBaseSize + SEPARATION;
m_buttonBaseSize = CaptureButton::buttonBaseSize();
m_buttonExtendedSize = m_buttonBaseSize + m_separator;
}
bool ButtonHandler::contains(const QPoint &p) const {
@@ -360,7 +361,7 @@ bool ButtonHandler::contains(const QPoint &p) const {
bool firstIsTopLeft = (first.x() <= last.x() && first.y() <= last.y());
QPoint topLeft = firstIsTopLeft ? first : last;
QPoint bottonRight = firstIsTopLeft ? last : first;
topLeft += QPoint(-SEPARATION, -SEPARATION);
topLeft += QPoint(-m_separator, -m_separator);
bottonRight += QPoint(m_buttonExtendedSize, m_buttonExtendedSize);
QRegion r(QRect(topLeft, bottonRight).normalized());
return r.contains(p);

View File

@@ -73,7 +73,10 @@ private:
QRect m_limits;
QRect m_selection;
int m_separator;
// aux methods
void init();
void resetRegionTrack();
void updateBlockedSides();
void expandSelection();

View File

@@ -25,14 +25,13 @@
#include <QToolTip>
#include <QMouseEvent>
#include <QGraphicsDropShadowEffect>
#include <QApplication>
// Button represents a single button of the capture widget, it can enable
// multiple functionality.
namespace {
const int BUTTON_SIZE = 30;
qreal getColorLuma(const QColor &c) {
return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
}
@@ -66,8 +65,8 @@ void CaptureButton::initButton() {
connect(this, &CaptureButton::pressed, m_tool, &CaptureTool::onPressed);
setFocusPolicy(Qt::NoFocus);
resize(BUTTON_SIZE, BUTTON_SIZE);
setMask(QRegion(QRect(-1,-1,BUTTON_SIZE+2, BUTTON_SIZE+2), QRegion::Ellipse));
resize(buttonBaseSize(), buttonBaseSize());
setMask(QRegion(QRect(-1,-1,buttonBaseSize()+2, buttonBaseSize()+2), QRegion::Ellipse));
setToolTip(m_tool->description());
@@ -75,7 +74,7 @@ void CaptureButton::initButton() {
m_emergeAnimation->setEasingCurve(QEasingCurve::InOutQuad);
m_emergeAnimation->setDuration(80);
m_emergeAnimation->setStartValue(QSize(0, 0));
m_emergeAnimation->setEndValue(QSize(BUTTON_SIZE, BUTTON_SIZE));
m_emergeAnimation->setEndValue(QSize(buttonBaseSize(), buttonBaseSize()));
auto dsEffect = new QGraphicsDropShadowEffect(this);
dsEffect->setBlurRadius(5);
@@ -104,7 +103,7 @@ QString CaptureButton::globalStyleSheet() {
QString color = iconIsWhiteByColor(mainColor) ? "white" : "black";
return baseSheet.arg(mainColor.name()).arg(contrast.name())
.arg(BUTTON_SIZE/2).arg(color);
.arg(buttonBaseSize()/2).arg(color);
}
QString CaptureButton::styleSheet() const {
@@ -119,7 +118,7 @@ QString CaptureButton::styleSheet() const {
QString color = iconIsWhiteByColor(m_mainColor) ? "white" : "black";
return baseSheet.arg(m_mainColor.name()).arg(contrast.name())
.arg(BUTTON_SIZE/2).arg(color);
.arg(buttonBaseSize()/2).arg(color);
}
// get icon returns the icon for the type of button
@@ -162,7 +161,7 @@ void CaptureButton::setColor(const QColor &c) {
// getButtonBaseSize returns the base size of the buttons
size_t CaptureButton::buttonBaseSize() {
return BUTTON_SIZE;
return QApplication::fontMetrics().height() * 2.2 * qApp->devicePixelRatio();
}
bool CaptureButton::iconIsWhiteByColor(const QColor &c) {

View File

@@ -42,13 +42,6 @@
// CaptureWidget is the main component used to capture the screen. It contains an
// are of selection with its respective buttons.
namespace {
// size of the handlers at the corners of the selection
const int HANDLE_SIZE = 9;
} // unnamed namespace
// enableSaveWIndow
CaptureWidget::CaptureWidget(const uint id, const QString &forcedSavePath,
QWidget *parent) :
@@ -64,7 +57,8 @@ CaptureWidget::CaptureWidget(const uint id, const QString &forcedSavePath,
setAttribute(Qt::WA_DeleteOnClose);
// create selection handlers
QRect baseRect(0, 0, HANDLE_SIZE, HANDLE_SIZE);
QRect baseRect(0, 0, handleSize(), handleSize());
m_TLHandle = baseRect; m_TRHandle = baseRect;
m_BLHandle = baseRect; m_BRHandle = baseRect;
m_LHandle = baseRect; m_THandle = baseRect;
@@ -571,7 +565,7 @@ void CaptureWidget::initShortcuts() {
void CaptureWidget::updateHandles() {
QRect r = m_selection.normalized().adjusted(0, 0, -1, -1);
int s2 = HANDLE_SIZE / 2;
int s2 = handleSize() / 2;
m_TLHandle.moveTopLeft(QPoint(r.x() - s2, r.y() - s2));
m_TRHandle.moveTopRight(QPoint(r.right() + s2, r.y() - s2));
@@ -626,6 +620,11 @@ void CaptureWidget::updateCursor() {
}
int CaptureWidget::handleSize() {
return (QApplication::fontMetrics().height() * 0.7) *
qApp->devicePixelRatio();
}
void CaptureWidget::copyScreenshot() {
m_captureDone = true;
hide();

View File

@@ -123,6 +123,9 @@ private:
void updateSizeIndicator();
void updateCursor();
// size of the handlers at the corners of the selection
int handleSize();
QRect extendedSelection() const;
QVector<CaptureModification*> m_modifications;
QPointer<CaptureButton> m_sizeIndButton;

View File

@@ -20,6 +20,7 @@
#include "src/capture/widget/capturebutton.h"
#include <QTimer>
#include <QPainter>
#include <QApplication>
NotifierBox::NotifierBox(QWidget *parent) : QWidget(parent) {
m_timer = new QTimer(this);
@@ -30,7 +31,10 @@ NotifierBox::NotifierBox(QWidget *parent) : QWidget(parent) {
m_foregroundColor = (CaptureButton::iconIsWhiteByColor(m_bgColor) ?
Qt::white : Qt::black);
m_bgColor.setAlpha(180);
setFixedSize(QSize(46, 46));
const int size = (CaptureButton::buttonBaseSize() +
CaptureButton::buttonBaseSize()/2) *
qApp->devicePixelRatio();
setFixedSize(QSize(size, size));
}
void NotifierBox::enterEvent(QEvent *) {

View File

@@ -19,6 +19,7 @@
#include <QPaintEvent>
#include <QPainter>
#include <QTimer>
#include <QApplication>
#define OFFSET 5
@@ -26,7 +27,8 @@ LoadSpinner::LoadSpinner(QWidget *parent) :
QWidget(parent), m_startAngle(0), m_span(0), m_growing(true)
{
setAttribute(Qt::WA_TranslucentBackground);
setFixedSize(100, 100);
const int size = QApplication::fontMetrics().height() * 8;
setFixedSize(size, size);
updateFrame();
// init timer
m_timer = new QTimer(this);

View File

@@ -18,6 +18,7 @@
#include "applauncherwidget.h"
#include "src/utils/filenamehandler.h"
#include "src/capture/workers/launcher/launcheritemdelegate.h"
#include "src/capture/widget/capturebutton.h"
#include "src/utils/confighandler.h"
#include "terminallauncher.h"
#include <QDir>
@@ -155,7 +156,8 @@ void AppLauncherWidget::searchChanged(const QString &text) {
void AppLauncherWidget::initListWidget() {
m_tabWidget = new QTabWidget;
m_tabWidget->setIconSize(QSize(30, 30));
const int size = CaptureButton::buttonBaseSize();
m_tabWidget->setIconSize(QSize(size, size));
for (auto const& i : catIconNames.toStdMap()) {
const QString &cat = i.first;
@@ -219,7 +221,6 @@ void AppLauncherWidget::configureListView(QListWidget *widget) {
widget->setSpacing(4);
widget->setFlow(QListView::LeftToRight);
widget->setDragEnabled(false);
widget->setMinimumSize(375, 210);
connect(widget, &QListWidget::clicked,
this, &AppLauncherWidget::launch);
}

View File

@@ -16,6 +16,7 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "launcheritemdelegate.h"
#include "src/capture/widget/capturebutton.h"
#include <QPainter>
LauncherItemDelegate::LauncherItemDelegate(QObject *parent) :
@@ -39,7 +40,7 @@ void LauncherItemDelegate::paint(
}
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
const int iconSide = 40;
const int iconSide = CaptureButton::buttonBaseSize() * 1.3;
const int halfIcon = iconSide/2;
const int halfWidth = rect.width()/2;
const int halfHeight = rect.height()/2;
@@ -59,5 +60,6 @@ QSize LauncherItemDelegate::sizeHint(
{
Q_UNUSED(option);
Q_UNUSED(index);
return QSize(110, 115);
const int size = CaptureButton::buttonBaseSize();
return QSize(size * 3.2, size * 3.7);
}

View File

@@ -32,7 +32,8 @@
ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
setAttribute(Qt::WA_DeleteOnClose);
setMinimumSize(400, 490);
const int size = CaptureButton::buttonBaseSize() * 12;
setMinimumSize(size, size);
setWindowIcon(QIcon(":img/flameshot.png"));
setWindowTitle(tr("Configuration"));

View File

@@ -80,8 +80,9 @@ void UIcolorEditor::initColorWheel() {
connect(m_colorWheel, &color_widgets::ColorWheel::colorChanged, this,
&UIcolorEditor::updateLocalColor);
m_colorWheel->setMinimumSize(100, 100);
m_colorWheel->setMaximumSize(170, 170);
const int size = CaptureButton::buttonBaseSize() * 3;
m_colorWheel->setMinimumSize(size, size);
m_colorWheel->setMaximumSize(size*2, size*2);
m_colorWheel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_colorWheel->setToolTip(tr("Change the color moving the selectors and see"
" the changes in the preview buttons."));
@@ -90,7 +91,7 @@ void UIcolorEditor::initColorWheel() {
}
void UIcolorEditor::initButtons() {
const int extraSize = 10;
const int extraSize = CaptureButton::buttonBaseSize() / 3;
int frameSize = CaptureButton::buttonBaseSize() + extraSize;
m_vLayout->addWidget(new QLabel(tr("Select a Button to modify it"), this));