diff --git a/src/capture/widget/buttonhandler.cpp b/src/capture/widget/buttonhandler.cpp index 9502b25d..eb5afca0 100644 --- a/src/capture/widget/buttonhandler.cpp +++ b/src/capture/widget/buttonhandler.cpp @@ -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 &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 positions = verticalPoints(center, addCounter, false); moveButtonsToPoints(positions, elemIndicator); @@ -179,7 +175,7 @@ QVector 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 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 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 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); diff --git a/src/capture/widget/buttonhandler.h b/src/capture/widget/buttonhandler.h index b04bc813..3b819e58 100644 --- a/src/capture/widget/buttonhandler.h +++ b/src/capture/widget/buttonhandler.h @@ -73,7 +73,10 @@ private: QRect m_limits; QRect m_selection; + int m_separator; + // aux methods + void init(); void resetRegionTrack(); void updateBlockedSides(); void expandSelection(); diff --git a/src/capture/widget/capturebutton.cpp b/src/capture/widget/capturebutton.cpp index eed3b9f3..c5923728 100644 --- a/src/capture/widget/capturebutton.cpp +++ b/src/capture/widget/capturebutton.cpp @@ -25,14 +25,13 @@ #include #include #include +#include // 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) { diff --git a/src/capture/widget/capturewidget.cpp b/src/capture/widget/capturewidget.cpp index 056ba0a1..254a3c0f 100644 --- a/src/capture/widget/capturewidget.cpp +++ b/src/capture/widget/capturewidget.cpp @@ -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(); diff --git a/src/capture/widget/capturewidget.h b/src/capture/widget/capturewidget.h index 5c55ed95..2e14aac2 100644 --- a/src/capture/widget/capturewidget.h +++ b/src/capture/widget/capturewidget.h @@ -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 m_modifications; QPointer m_sizeIndButton; diff --git a/src/capture/widget/notifierbox.cpp b/src/capture/widget/notifierbox.cpp index c7762557..81d9e7e1 100644 --- a/src/capture/widget/notifierbox.cpp +++ b/src/capture/widget/notifierbox.cpp @@ -20,6 +20,7 @@ #include "src/capture/widget/capturebutton.h" #include #include +#include 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 *) { diff --git a/src/capture/workers/imgur/loadspinner.cpp b/src/capture/workers/imgur/loadspinner.cpp index 454a1966..a32371d6 100644 --- a/src/capture/workers/imgur/loadspinner.cpp +++ b/src/capture/workers/imgur/loadspinner.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #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); diff --git a/src/capture/workers/launcher/applauncherwidget.cpp b/src/capture/workers/launcher/applauncherwidget.cpp index 6bf511d5..ac45692c 100644 --- a/src/capture/workers/launcher/applauncherwidget.cpp +++ b/src/capture/workers/launcher/applauncherwidget.cpp @@ -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 @@ -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); } diff --git a/src/capture/workers/launcher/launcheritemdelegate.cpp b/src/capture/workers/launcher/launcheritemdelegate.cpp index 09152b4f..8d8addb6 100644 --- a/src/capture/workers/launcher/launcheritemdelegate.cpp +++ b/src/capture/workers/launcher/launcheritemdelegate.cpp @@ -16,6 +16,7 @@ // along with Flameshot. If not, see . #include "launcheritemdelegate.h" +#include "src/capture/widget/capturebutton.h" #include LauncherItemDelegate::LauncherItemDelegate(QObject *parent) : @@ -39,7 +40,7 @@ void LauncherItemDelegate::paint( } QIcon icon = index.data(Qt::DecorationRole).value(); - 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); } diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp index 31693636..0944dff9 100644 --- a/src/config/configwindow.cpp +++ b/src/config/configwindow.cpp @@ -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")); diff --git a/src/config/uicoloreditor.cpp b/src/config/uicoloreditor.cpp index 919bdc76..c54be2f9 100644 --- a/src/config/uicoloreditor.cpp +++ b/src/config/uicoloreditor.cpp @@ -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));