diff --git a/config/buttonlistview.cpp b/config/buttonlistview.cpp new file mode 100644 index 00000000..4159bfe0 --- /dev/null +++ b/config/buttonlistview.cpp @@ -0,0 +1,61 @@ +#include "buttonlistview.h" +#include "capture/button.h" +#include +#include +#include + +ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) { + setMouseTracking(true); + //setFocusPolicy(Qt::NoFocus); + + QSettings settings; + m_listButtons = settings.value("buttons").value >(); + initButtonList(); + + connect(this, &QListWidget::itemChanged, this, + &ButtonListView::updateActiveButtons); + connect(this, &QListWidget::itemClicked, this, + &ButtonListView::reverseItemCheck); +} + +void ButtonListView::initButtonList() { + for (int i = 0; i != static_cast(Button::Type::last); ++i) { + auto t = static_cast(i); + QListWidgetItem *buttonItem = new QListWidgetItem(this); + + bool iconsAreWhite = false; + QString bgColor = this->palette().color(QWidget::backgroundRole()).name(); + // when the background is lighter than gray, it uses the white icons + if (bgColor < QColor(Qt::gray).name()) { + iconsAreWhite = true; + } + buttonItem->setIcon(Button::getIcon(t, iconsAreWhite)); + buttonItem->setFlags(Qt::ItemIsUserCheckable); + + buttonItem->setText(Button::getTypeName(t)); + buttonItem->setToolTip(Button::getTypeTooltip(t)); + if (m_listButtons.contains(i)) { + buttonItem->setCheckState(Qt::Checked); + } else { + buttonItem->setCheckState(Qt::Unchecked); + } + } +} + +void ButtonListView::updateActiveButtons(QListWidgetItem *item) { + int buttonIndex = static_cast(Button::getTypeByName(item->text())); + if (item->checkState() == Qt::Checked) { + m_listButtons.append(buttonIndex); + } else { + m_listButtons.removeOne(buttonIndex); + } + QSettings().setValue("buttons", QVariant::fromValue(m_listButtons)); +} + +void ButtonListView::reverseItemCheck(QListWidgetItem *item){ + if (item->checkState() == Qt::Checked) { + item->setCheckState(Qt::Unchecked); + } else { + item->setCheckState(Qt::Checked); + } +} diff --git a/config/buttonlistview.h b/config/buttonlistview.h new file mode 100644 index 00000000..bec3af6e --- /dev/null +++ b/config/buttonlistview.h @@ -0,0 +1,21 @@ +#ifndef BUTTONLISTVIEW_H +#define BUTTONLISTVIEW_H + +#include + +class ButtonListView : public QListWidget { +public: + ButtonListView(QWidget *parent= 0); + +private slots: + void updateActiveButtons(QListWidgetItem *); + void reverseItemCheck(QListWidgetItem *); + +protected: + void initButtonList(); + +private: + QList m_listButtons; +}; + +#endif // BUTTONLISTVIEW_H diff --git a/config/configwindow.cpp b/config/configwindow.cpp new file mode 100644 index 00000000..33b14803 --- /dev/null +++ b/config/configwindow.cpp @@ -0,0 +1,43 @@ +// Copyright 2017 Alejandro Sirgo Rica +// +// This file is part of Flameshot. +// +// Flameshot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Flameshot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Flameshot. If not, see . + +#include "configwindow.h" +#include "capture/button.h" +#include "config/buttonlistview.h" +#include +#include +#include +#include + +// ConfigWindow contains the menus where you can configure the application + +ConfigWindow::ConfigWindow(QWidget *parent) : QWidget(parent){ + setAttribute(Qt::WA_DeleteOnClose); + setWindowIcon(QIcon(":img/flameshot.svg")); + setWindowTitle(tr("Configuration")); + + QVBoxLayout *baseLayout = new QVBoxLayout(this); + + QLabel *buttonSelectLabel = new QLabel("Choose the buttons to enable", this); + baseLayout->addWidget(buttonSelectLabel); + + ButtonListView *m_buttonListView = new ButtonListView(this); + m_buttonListView->setFlow(QListWidget::TopToBottom); + + baseLayout->addWidget(m_buttonListView); + show(); +} diff --git a/configwindow.h b/config/configwindow.h similarity index 86% rename from configwindow.h rename to config/configwindow.h index 431a04c9..47f2c562 100644 --- a/configwindow.h +++ b/config/configwindow.h @@ -28,14 +28,8 @@ class ConfigWindow : public QWidget { public: explicit ConfigWindow(QWidget *parent = 0); -private slots: - void updateActiveButtons(QListWidgetItem *); - private: - void initButtonList(); - QList m_listButtons; - QListWidget *m_buttonListView; }; #endif // CONFIGURATION_H diff --git a/configwindow.cpp b/configwindow.cpp deleted file mode 100644 index fb40d706..00000000 --- a/configwindow.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2017 Alejandro Sirgo Rica -// -// This file is part of Flameshot. -// -// Flameshot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Flameshot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Flameshot. If not, see . - -#include "configwindow.h" -#include "capture/button.h" -#include -#include -#include -#include -#include -#include -#include - -// ConfigWindow contains the menus where you can configure the application - -ConfigWindow::ConfigWindow(QWidget *parent) : QWidget(parent){ - setAttribute(Qt::WA_DeleteOnClose); - setWindowIcon(QIcon(":img/flameshot.svg")); - setWindowTitle(tr("Configuration")); - - QVBoxLayout *baseLayout = new QVBoxLayout(this); - - QLabel *buttonSelectLabel = new QLabel("Choose the buttons to enable", this); - baseLayout->addWidget(buttonSelectLabel); - - m_buttonListView = new QListWidget(this); - m_buttonListView->setFlow(QListWidget::TopToBottom); - m_buttonListView->setMouseTracking(true); - - QSettings settings; - m_listButtons = settings.value("buttons").value >(); - initButtonList(); - - connect(m_buttonListView, &QListWidget::itemChanged, this, - &ConfigWindow::updateActiveButtons); - - baseLayout->addWidget(m_buttonListView); - show(); -} - -void ConfigWindow::initButtonList() { - for (int i = 0; i != static_cast(Button::Type::last); ++i) { - auto t = static_cast(i); - QListWidgetItem *buttonItem = new QListWidgetItem(m_buttonListView); - - bool iconsAreWhite = false; - QString bgColor = this->palette().color(QWidget::backgroundRole()).name(); - // when the background is lighter than gray, it uses the white icons - if (bgColor < QColor(Qt::gray).name()) { - iconsAreWhite = true; - } - buttonItem->setIcon(Button::getIcon(t, iconsAreWhite)); - - buttonItem->setText(Button::getTypeName(t)); - buttonItem->setToolTip(Button::getTypeTooltip(t)); - if (m_listButtons.contains(i)) { - buttonItem->setCheckState(Qt::Checked); - } else { - buttonItem->setCheckState(Qt::Unchecked); - } - } -} - -void ConfigWindow::updateActiveButtons(QListWidgetItem *item) { - int buttonIndex = static_cast(Button::getTypeByName(item->text())); - if (item->checkState() == Qt::Checked) { - m_listButtons.append(buttonIndex); - } else { - m_listButtons.removeOne(buttonIndex); - } - QSettings().setValue("buttons", QVariant::fromValue(m_listButtons)); -} diff --git a/flameshot.pro b/flameshot.pro index c5da78f6..4159984d 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -37,11 +37,12 @@ SOURCES += main.cpp\ capture/button.cpp \ capture/buttonhandler.cpp \ infowindow.cpp \ - configwindow.cpp \ + config/configwindow.cpp \ capture/screenshot.cpp \ capture/capturewidget.cpp \ capture/capturemodification.cpp \ - capture/colorpicker.cpp + capture/colorpicker.cpp \ + config/buttonlistview.cpp HEADERS += \ nativeeventfilter.h \ @@ -49,11 +50,12 @@ HEADERS += \ capture/button.h \ capture/buttonhandler.h \ infowindow.h \ - configwindow.h \ + config/configwindow.h \ capture/screenshot.h \ capture/capturewidget.h \ capture/capturemodification.h \ - capture/colorpicker.h + capture/colorpicker.h \ + config/buttonlistview.h RESOURCES += \ graphics.qrc