From 88c00f0cc33cfa4645086a3443796d4c612c1f67 Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Wed, 24 May 2017 21:05:59 +0200 Subject: [PATCH] Code cleanup --- src/capture/button.cpp | 8 ++- src/capture/buttonhandler.cpp | 10 +-- src/capture/capturemodification.cpp | 3 +- src/capture/capturewidget.cpp | 7 ++- src/capture/colorpicker.cpp | 3 +- src/capture/screenshot.cpp | 12 ++-- src/config/buttonlistview.cpp | 1 - src/config/configwindow.cpp | 2 +- src/config/uicoloreditor.cpp | 7 +-- src/config/uicoloreditor.h | 3 +- src/controller.cpp | 12 ++-- src/infowindow.cpp | 3 +- src/nativeeventfilter.cpp | 4 +- translation/Internationalization_es.ts | 87 ++++++++++++++------------ 14 files changed, 91 insertions(+), 71 deletions(-) diff --git a/src/capture/button.cpp b/src/capture/button.cpp index e9367e14..f90247fb 100644 --- a/src/capture/button.cpp +++ b/src/capture/button.cpp @@ -31,7 +31,8 @@ namespace { } Button::Button(const Type t, QWidget *parent) : QPushButton(parent), - m_buttonType(t), m_pressed(false) { + m_buttonType(t), m_pressed(false) +{ initButton(); if (t == Button::Type::selectionIndicator) { @@ -43,7 +44,8 @@ Button::Button(const Type t, QWidget *parent) : QPushButton(parent), } Button::Button(const Button::Type t, const bool isWhite, QWidget *parent) - : QPushButton(parent), m_buttonType(t), m_pressed(false) { + : QPushButton(parent), m_buttonType(t), m_pressed(false) +{ initButton(); if (t == Button::Type::selectionIndicator) { @@ -143,7 +145,7 @@ QString Button::getStyle() { QColor mainColor = settings.value("uiColor").value(); return getStyle(mainColor); } -#include + QString Button::getStyle(const QColor &mainColor) { QString baseSheet = "Button { border-radius: %3;" "background-color: %1; color: %4 }" diff --git a/src/capture/buttonhandler.cpp b/src/capture/buttonhandler.cpp index 03b882a4..84f9df86 100644 --- a/src/capture/buttonhandler.cpp +++ b/src/capture/buttonhandler.cpp @@ -57,7 +57,8 @@ size_t ButtonHandler::size() const { // When the selection is too small it works on a virtual selection with // the original in the center. void ButtonHandler::updatePosition(const QRect &selection, - const QRect &limits) { + const QRect &limits) +{ const QVector::size_type vecLength = m_vectorButtons.size(); if (vecLength == 0) { return; @@ -250,7 +251,8 @@ void ButtonHandler::updatePosition(const QRect &selection, // starts from a known center and keeps adding elements horizontally // and returns the computed positions. QVector ButtonHandler::getHPoints( - const QPoint ¢er, const int elements) const { + const QPoint ¢er, const int elements) const +{ QVector res; QPoint left, right; @@ -275,8 +277,8 @@ QVector ButtonHandler::getHPoints( // starts from a known center and keeps adding elements vertically // and returns the computed positions. QVector ButtonHandler::getVPoints( - const QPoint ¢er, const int elements) const { - + const QPoint ¢er, const int elements) const +{ QVector res; QPoint up, down; if (elements % 2 == 0) { diff --git a/src/capture/capturemodification.cpp b/src/capture/capturemodification.cpp index 42a5f680..5a05de31 100644 --- a/src/capture/capturemodification.cpp +++ b/src/capture/capturemodification.cpp @@ -22,7 +22,8 @@ // by the user. CaptureModification::CaptureModification(const Button::Type t, const QPoint p, - const QColor c) : m_color(c), m_type(t) { + const QColor c) : m_color(c), m_type(t) +{ m_coords.append(p); if (m_type == Button::Type::circle || m_type == Button::Type::rectangle || m_type == Button::Type::arrow || m_type == Button::Type::line || diff --git a/src/capture/capturewidget.cpp b/src/capture/capturewidget.cpp index 465ccd64..23eddfb0 100644 --- a/src/capture/capturewidget.cpp +++ b/src/capture/capturewidget.cpp @@ -53,8 +53,8 @@ namespace { CaptureWidget::CaptureWidget(QWidget *parent) : QWidget(parent), m_mouseOverHandle(0), m_mouseIsClicked(false), m_rightClick(false), m_newSelection(false), m_grabbing(false), - m_onButton(false), m_state(Button::Type::move) { - + m_onButton(false), m_state(Button::Type::move) +{ setAttribute(Qt::WA_DeleteOnClose); // create selection handlers QRect baseRect(0, 0, HANDLE_SIZE, HANDLE_SIZE); @@ -196,7 +196,8 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) { m_mousePos = e->pos(); if (m_newSelection) { - m_selection = QRect(m_dragStartPoint, limitPointToRect(m_mousePos, rect())).normalized(); + m_selection = QRect(m_dragStartPoint, limitPointToRect( + m_mousePos, rect())).normalized(); } else if (m_mouseOverHandle == 0) { // Moving the whole selection QRect r = rect().normalized(), s = m_selectionBeforeDrag.normalized(); diff --git a/src/capture/colorpicker.cpp b/src/capture/colorpicker.cpp index a094dfc3..db101e2e 100644 --- a/src/capture/colorpicker.cpp +++ b/src/capture/colorpicker.cpp @@ -22,7 +22,8 @@ ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent), - m_colorAreaSize(18) { + m_colorAreaSize(18) +{ setMouseTracking(true); // save the color values in member variables for faster access QSettings settings; diff --git a/src/capture/screenshot.cpp b/src/capture/screenshot.cpp index 576ad523..3f5e4c1f 100644 --- a/src/capture/screenshot.cpp +++ b/src/capture/screenshot.cpp @@ -135,7 +135,8 @@ QPixmap Screenshot::paintModification(const CaptureModification &modification) { // paintTemporalModification paints a modification without updating the // member pixmap QPixmap Screenshot::paintTemporalModification( - const CaptureModification &modification) { + const CaptureModification &modification) +{ QPixmap tempPix = m_modifiedScreenshot; QPainter painter(&tempPix); if (modification.getType() != Button::Type::pencil) { @@ -148,7 +149,8 @@ QPixmap Screenshot::paintTemporalModification( // paintBaseModifications overrides the modifications of the screenshot // with new ones. QPixmap Screenshot::paintBaseModifications( - const QVector &m) { + const QVector &m) +{ m_modifiedScreenshot = m_baseScreenshot; for (const CaptureModification modification: m) { paintModification(modification); @@ -201,7 +203,8 @@ namespace { // paintInPainter is an aux method to prevent duplicated code, it draws the // passed modification to the painter. void Screenshot::paintInPainter(QPainter &painter, - const CaptureModification &modification) { + const CaptureModification &modification) +{ painter.setPen(QPen(modification.getColor(), 2)); QVector points = modification.getPoints(); switch (modification.getType()) { @@ -234,7 +237,8 @@ void Screenshot::paintInPainter(QPainter &painter, } void Screenshot::uploadToImgur(QNetworkAccessManager *accessManager, - const QRect &selection) { + const QRect &selection) +{ QString title ="flameshot_screenshot"; QString datetime = QDateTime().toString(); QString description = "flameshot " + datetime; diff --git a/src/config/buttonlistview.cpp b/src/config/buttonlistview.cpp index 373e5a72..490e9d61 100644 --- a/src/config/buttonlistview.cpp +++ b/src/config/buttonlistview.cpp @@ -23,7 +23,6 @@ ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) { setMouseTracking(true); - //setFocusPolicy(Qt::NoFocus); QSettings settings; m_listButtons = settings.value("buttons").value >(); diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp index ad4494eb..9afdb319 100644 --- a/src/config/configwindow.cpp +++ b/src/config/configwindow.cpp @@ -26,7 +26,7 @@ // ConfigWindow contains the menus where you can configure the application -ConfigWindow::ConfigWindow(QWidget *parent) : QWidget(parent){ +ConfigWindow::ConfigWindow(QWidget *parent) : QWidget(parent) { setAttribute(Qt::WA_DeleteOnClose); setFixedSize(280, 400); setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); diff --git a/src/config/uicoloreditor.cpp b/src/config/uicoloreditor.cpp index f9923e01..224c1655 100644 --- a/src/config/uicoloreditor.cpp +++ b/src/config/uicoloreditor.cpp @@ -77,13 +77,10 @@ void UIcolorEditor::initButton() { m_button->move(m_button->x() + extraSize/2, m_button->y() + extraSize/2); vLayout->addWidget(frame); -// QString bgColor = this->palette().color(QWidget::backgroundRole()).name(); -// if (bgColor < QColor(Qt::gray).name()) { -// iconsAreWhite = true; - // } + m_button->setToolTip(tr("Color preview")); } -QMap UIcolorEditor::iconColorToString = { +UIcolorEditor::colorToStringMap UIcolorEditor::iconColorToString = { {iconColor::White, QT_TR_NOOP("White Icon")}, {iconColor::Black, QT_TR_NOOP("Black Icon")} }; diff --git a/src/config/uicoloreditor.h b/src/config/uicoloreditor.h index 7a96bd49..d9529338 100644 --- a/src/config/uicoloreditor.h +++ b/src/config/uicoloreditor.h @@ -46,7 +46,8 @@ private: void initComboBox(); enum class iconColor {Black, White}; - static QMap iconColorToString; + typedef QMap colorToStringMap; + static colorToStringMap iconColorToString; }; #endif // UICOLORPICKER_H diff --git a/src/controller.cpp b/src/controller.cpp index a5918b2f..fae0b84a 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -31,7 +31,8 @@ // launches the capture widget Controller::Controller(QObject *parent) : QObject(parent), - m_captureWindow(nullptr) { + m_captureWindow(nullptr) +{ // required for the button serialization qRegisterMetaTypeStreamOperators >("QList"); createActions(); @@ -53,13 +54,16 @@ Controller::Controller(QObject *parent) : QObject(parent), // creates the items of the trayIcon void Controller::createActions() { m_configAction = new QAction(tr("&Configuration"), this); - connect(m_configAction, &QAction::triggered, this, &Controller::openConfigWindow); + connect(m_configAction, &QAction::triggered, this, + &Controller::openConfigWindow); m_infoAction = new QAction(tr("&Information"), this); - connect(m_infoAction, &QAction::triggered, this, &Controller::openInfoWindow); + connect(m_infoAction, &QAction::triggered, this, + &Controller::openInfoWindow); m_quitAction = new QAction(tr("&Quit"), this); - connect(m_quitAction, &QAction::triggered, qApp, &QCoreApplication::quit); + connect(m_quitAction, &QAction::triggered, qApp, + &QCoreApplication::quit); } // creates the trayIcon diff --git a/src/infowindow.cpp b/src/infowindow.cpp index cfc3e09b..65ac3d11 100644 --- a/src/infowindow.cpp +++ b/src/infowindow.cpp @@ -87,5 +87,6 @@ void InfoWindow::initInfoTable() { table->resizeColumnsToContents(); table->resizeRowsToContents(); table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); - table->horizontalHeader()->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + table->horizontalHeader()->setSizePolicy(QSizePolicy::Expanding, + QSizePolicy::Expanding); } diff --git a/src/nativeeventfilter.cpp b/src/nativeeventfilter.cpp index 83efdbcf..30da3a6d 100644 --- a/src/nativeeventfilter.cpp +++ b/src/nativeeventfilter.cpp @@ -36,7 +36,9 @@ NativeEventFilter::NativeEventFilter(QObject *parent) : QObject(parent) { setShortcut(); } -bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result) { +bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType, + void *message, long *result) +{ Q_UNUSED(eventType) Q_UNUSED(result) diff --git a/translation/Internationalization_es.ts b/translation/Internationalization_es.ts index 3ed3a295..535c6635 100644 --- a/translation/Internationalization_es.ts +++ b/translation/Internationalization_es.ts @@ -4,162 +4,162 @@ Button - + Shows the dimensions of the selection (X Y) Muestra la dimensión de ls selección (X Y) - + Sets the visibility of the mouse pointer Selecciona la visibilidad del puntero del ratón - + Leaves the capture screen Cierra la pantalla de captura - + Copies the selecion into the clipboard Copia la selección al portapapeles - + Opens the save image window Abre la ventana de guardar imagen - + Sets the paint tool to a pencil Establece el lápiz como herramienta de dibujo - + Sets the paint tool to a line drawer Establece la línea como herramienta de dibujo - + Sets the paint tool to an arrow drawer Establece la flecha como herramienta de dibujo - + Sets the paint tool to a rectagle drawer Establece el rectángulo como herramienta de dibujo - + Sets the paint tool to a circle drawer Establece el círculo como herramienta de dibujo - + Sets the paint tool to a marker Establece el marcador como herramienta de dibujo - + Sets the paint tool to a text creator Establece el texto como herramienta de dibujo - + Opens the color picker widget Abre el selector de color - + Undo the last modification Deshace la última modificación - + Upload the selection to Imgur Sube la selección a Imgur - + Move the selection area Mueve la selección - + Selection Size Indicator Indicador de Tamaño de Selección - + Mouse Visibility Visibilidad del Ratón - + Exit Salir - + Copy Copiar - + Save Guardar - + Pencil Lápiz - + Line Línea - + Arrow Flecha - + Rectangle Rectángulo - + Circle Círculo - + Marker Marcador - + Text Texto - + Color Picker Selector de Color - + Undo Deshacer - + Image Uploader Subir Imagen - + Move Mover Selección @@ -167,7 +167,7 @@ CaptureWidget - + Uploading image... Subiendo imagen... @@ -175,17 +175,17 @@ ConfigWindow - + Configuration Configuración - + UI color editor Editor de color de interfaz - + Button selection Selección de botones @@ -193,17 +193,17 @@ Controller - + &Configuration &Configuración - + &Information &Información - + &Quit &Salir @@ -302,12 +302,17 @@ UIcolorEditor - + + Color preview + Previsualización de color + + + White Icon Icono Blanco - + Black Icon Icono Negro