1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 13:33:50 +03:00

drop sub handler detailsoptionshandler

--drop the sub handler detailsoptionshandler
because the new design wont have tabs like the main
settings window does. Views table will be provided
through a new sub dialog.
This commit is contained in:
Michail Vourlakos 2020-07-29 22:00:37 +03:00
parent 029090a2de
commit 3c94aa8d75
5 changed files with 123 additions and 296 deletions

View File

@ -1,7 +1,6 @@
set(lattedock-app_SRCS
${lattedock-app_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/detailshandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detailsoptionshandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/generichandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tabpreferenceshandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tablayoutshandler.cpp

View File

@ -23,11 +23,16 @@
// local
#include "ui_detailsdialog.h"
#include "../controllers/layoutscontroller.h"
#include "../data/layoutdata.h"
#include "../data/layoutstable.h"
#include "../delegates/colorcmbitemdelegate.h"
#include "../dialogs/detailsdialog.h"
#include "../models/colorsmodel.h"
#include "../models/layoutsmodel.h"
// Qt
#include <QColorDialog>
#include <QFileDialog>
namespace Latte {
namespace Settings {
namespace Handler {
@ -35,12 +40,10 @@ namespace Handler {
DetailsHandler::DetailsHandler(Dialog::DetailsDialog *parentDialog)
: Generic(parentDialog),
m_parentDialog(parentDialog),
m_ui(m_parentDialog->ui())
m_ui(m_parentDialog->ui()),
m_colorsModel(new Model::Colors(this, parentDialog->corona()))
{
init();
//! create it after initializing
m_optionsHandler = new DetailsOptionsHandler(parentDialog, this);
}
DetailsHandler::~DetailsHandler()
@ -49,15 +52,47 @@ DetailsHandler::~DetailsHandler()
void DetailsHandler::init()
{
m_proxyModel = new QSortFilterProxyModel(this);
m_proxyModel->setSourceModel(m_parentDialog->layoutsController()->baseModel());
m_proxyModel->setSortRole(Model::Layouts::SORTINGROLE);
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
m_proxyModel->sort(Model::Layouts::NAMECOLUMN, Qt::AscendingOrder);
//! Layouts
m_layoutsProxyModel = new QSortFilterProxyModel(this);
m_layoutsProxyModel->setSourceModel(m_parentDialog->layoutsController()->baseModel());
m_layoutsProxyModel->setSortRole(Model::Layouts::SORTINGROLE);
m_layoutsProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
m_layoutsProxyModel->sort(Model::Layouts::NAMECOLUMN, Qt::AscendingOrder);
m_ui->layoutsCmb->setModel(m_proxyModel);
m_ui->layoutsCmb->setModel(m_layoutsProxyModel);
m_ui->layoutsCmb->setModelColumn(Model::Layouts::NAMECOLUMN);
//! Background Pattern
m_backButtonsGroup = new QButtonGroup(this);
m_backButtonsGroup->addButton(m_ui->colorRadioBtn, Latte::Layout::ColorBackgroundStyle);
m_backButtonsGroup->addButton(m_ui->backRadioBtn, Latte::Layout::PatternBackgroundStyle);
m_backButtonsGroup->setExclusive(true);
m_ui->colorsCmb->setItemDelegate(new Details::Delegate::ColorCmbBoxItem(this));
m_ui->colorsCmb->setModel(m_colorsModel);
connect(m_backButtonsGroup, static_cast<void(QButtonGroup::*)(int, bool)>(&QButtonGroup::buttonToggled),
[ = ](int id, bool checked) {
if (checked) {
//m_layoutsController->setInMultipleMode(id == Latte::Types::MultipleLayouts);
}
});
connect(m_ui->backgroundBtn, &QPushButton::pressed, this, &DetailsHandler::selectBackground);
connect(m_ui->textColorBtn, &QPushButton::pressed, this, &DetailsHandler::selectTextColor);
//! Options
connect(m_ui->inMenuChk, &QCheckBox::stateChanged, this, [&]() {
setIsShownInMenu(m_ui->inMenuChk->isChecked());
});
connect(m_ui->borderlessChk, &QCheckBox::stateChanged, this, [&]() {
setHasDisabledBorders(m_ui->borderlessChk->isChecked());
});
connect(this, &DetailsHandler::currentLayoutChanged, this, &DetailsHandler::reload);
reload();
//! connect combobox after the selected layout has been loaded
@ -70,6 +105,26 @@ void DetailsHandler::reload()
c_data = o_data;
m_ui->layoutsCmb->setCurrentText(o_data.name);
loadLayout(c_data);
}
void DetailsHandler::loadLayout(const Data::Layout &data)
{
if (data.backgroundStyle == Latte::Layout::ColorBackgroundStyle) {
m_ui->colorRadioBtn->setChecked(true);
} else {
m_ui->backRadioBtn->setChecked(true);
}
m_ui->colorPatternWidget->setBackground(m_parentDialog->layoutsController()->colorPath(data.color));
m_ui->backPatternWidget->setBackground(data.background);
m_ui->colorPatternWidget->setTextColor(Layout::AbstractLayout::defaultTextColor(data.color));
m_ui->backPatternWidget->setTextColor(data.textColor);
m_ui->inMenuChk->setChecked(data.isShownInMenu);
m_ui->borderlessChk->setChecked(data.hasDisabledBorders);
}
Data::Layout DetailsHandler::currentData() const
@ -106,7 +161,7 @@ void DetailsHandler::save()
void DetailsHandler::on_currentIndexChanged(int row)
{
QString layoutId = m_proxyModel->data(m_proxyModel->index(row, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
QString layoutId = m_layoutsProxyModel->data(m_layoutsProxyModel->index(row, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
m_parentDialog->layoutsController()->selectRow(layoutId);
reload();
@ -133,6 +188,42 @@ void DetailsHandler::setHasDisabledBorders(bool disabled)
c_data.hasDisabledBorders = disabled;
}
void DetailsHandler::selectBackground()
{
QStringList mimeTypeFilters;
mimeTypeFilters << "image/jpeg" // will show "JPEG image (*.jpeg *.jpg)
<< "image/png"; // will show "PNG image (*.png)"
QFileDialog dialog(m_parentDialog);
dialog.setMimeTypeFilters(mimeTypeFilters);
QString background = m_ui->backPatternWidget->background();
if (background.startsWith("/") && QFileInfo(background).exists()) {
dialog.setDirectory(QFileInfo(background).absolutePath());
dialog.selectFile(background);
}
if (dialog.exec()) {
QStringList files = dialog.selectedFiles();
if (files.count() > 0) {
setBackground(files[0]);
}
}
}
void DetailsHandler::selectTextColor()
{
QColorDialog dialog(m_parentDialog);
dialog.setCurrentColor(QColor(m_ui->backPatternWidget->textColor()));
if (dialog.exec()) {
qDebug() << "layout selected text color: " << dialog.selectedColor().name();
setTextColor(dialog.selectedColor().name());
}
}
}
}
}

View File

@ -21,11 +21,12 @@
#ifndef DETAILSDIALOGHANDLER_H
#define DETAILSDIALOGHANDLER_H
//! local
// local
#include "generichandler.h"
#include "detailsoptionshandler.h"
#include "../data/layoutdata.h"
// Qt
#include <QButtonGroup>
#include <QSortFilterProxyModel>
namespace Ui {
@ -40,6 +41,14 @@ class DetailsDialog;
}
}
namespace Latte{
namespace Settings{
namespace Model {
class Colors;
}
}
}
namespace Latte {
namespace Settings {
@ -79,15 +88,22 @@ private:
private:
void init();
void selectBackground();
void selectTextColor();
void reload();
void loadLayout(const Data::Layout &data);
private:
Dialog::DetailsDialog *m_parentDialog{nullptr};
Ui::DetailsDialog *m_ui{nullptr};
DetailsOptionsHandler *m_optionsHandler{nullptr};
QSortFilterProxyModel *m_layoutsProxyModel{nullptr};
QSortFilterProxyModel *m_proxyModel{nullptr};
//! current data
Model::Colors *m_colorsModel{nullptr};
QButtonGroup *m_backButtonsGroup;
Data::Layout o_data;
Data::Layout c_data;

View File

@ -1,174 +0,0 @@
/*
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
*
* This file is part of Latte-Dock
*
* Latte-Dock 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 2 of
* the License, or (at your option) any later version.
*
* Latte-Dock 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "detailsoptionshandler.h"
// local
#include "ui_detailsdialog.h"
#include "detailshandler.h"
#include "../delegates/colorcmbitemdelegate.h"
#include "../dialogs/detailsdialog.h"
#include "../models/colorsmodel.h"
#include "../widgets/patternwidget.h"
#include "../../layout/abstractlayout.h"
// Qt
#include <QColorDialog>
#include <QFileDialog>
namespace Latte {
namespace Settings {
namespace Handler {
DetailsOptionsHandler::DetailsOptionsHandler(Dialog::DetailsDialog *parentDialog, DetailsHandler *parentHandler)
: Generic(parentDialog, parentHandler),
m_parentDialog(parentDialog),
m_ui(m_parentDialog->ui()),
m_parentHandler(parentHandler),
m_colorsModel(new Model::Colors(this, parentDialog->corona()))
{
init();
}
DetailsOptionsHandler::~DetailsOptionsHandler()
{
}
void DetailsOptionsHandler::init()
{
m_backButtonsGroup = new QButtonGroup(this);
m_backButtonsGroup->addButton(m_ui->colorRadioBtn, Latte::Layout::ColorBackgroundStyle);
m_backButtonsGroup->addButton(m_ui->backRadioBtn, Latte::Layout::PatternBackgroundStyle);
m_backButtonsGroup->setExclusive(true);
m_ui->colorsCmb->setItemDelegate(new Details::Delegate::ColorCmbBoxItem(this));
m_ui->colorsCmb->setModel(m_colorsModel);
connect(m_backButtonsGroup, static_cast<void(QButtonGroup::*)(int, bool)>(&QButtonGroup::buttonToggled),
[ = ](int id, bool checked) {
if (checked) {
//m_layoutsController->setInMultipleMode(id == Latte::Types::MultipleLayouts);
}
});
connect(m_ui->backgroundBtn, &QPushButton::pressed, this, &DetailsOptionsHandler::selectBackground);
connect(m_ui->textColorBtn, &QPushButton::pressed, this, &DetailsOptionsHandler::selectTextColor);
connect(m_ui->inMenuChk, &QCheckBox::stateChanged, this, [&]() {
m_parentHandler->setIsShownInMenu(m_ui->inMenuChk->isChecked());
});
connect(m_ui->borderlessChk, &QCheckBox::stateChanged, this, [&]() {
m_parentHandler->setHasDisabledBorders(m_ui->borderlessChk->isChecked());
});
connect(m_parentHandler, &DetailsHandler::currentLayoutChanged, this, &DetailsOptionsHandler::reload);
reload();
}
void DetailsOptionsHandler::reload()
{
loadLayout(m_parentHandler->currentData());
}
void DetailsOptionsHandler::loadLayout(const Data::Layout &data)
{
if (data.backgroundStyle == Latte::Layout::ColorBackgroundStyle) {
m_ui->colorRadioBtn->setChecked(true);
} else {
m_ui->backRadioBtn->setChecked(true);
}
m_ui->colorPatternWidget->setBackground(m_parentDialog->layoutsController()->colorPath(data.color));
m_ui->backPatternWidget->setBackground(data.background);
m_ui->colorPatternWidget->setTextColor(Layout::AbstractLayout::defaultTextColor(data.color));
m_ui->backPatternWidget->setTextColor(data.textColor);
m_ui->inMenuChk->setChecked(data.isShownInMenu);
m_ui->borderlessChk->setChecked(data.hasDisabledBorders);
}
bool DetailsOptionsHandler::dataAreChanged() const
{
return true;
}
bool DetailsOptionsHandler::inDefaultValues() const
{
//nothing special
return true;
}
void DetailsOptionsHandler::reset()
{
}
void DetailsOptionsHandler::resetDefaults()
{
//do nothing
}
void DetailsOptionsHandler::save()
{
}
void DetailsOptionsHandler::selectBackground()
{
QStringList mimeTypeFilters;
mimeTypeFilters << "image/jpeg" // will show "JPEG image (*.jpeg *.jpg)
<< "image/png"; // will show "PNG image (*.png)"
QFileDialog dialog(m_parentDialog);
dialog.setMimeTypeFilters(mimeTypeFilters);
QString background = m_ui->backPatternWidget->background();
if (background.startsWith("/") && QFileInfo(background).exists()) {
dialog.setDirectory(QFileInfo(background).absolutePath());
dialog.selectFile(background);
}
if (dialog.exec()) {
QStringList files = dialog.selectedFiles();
if (files.count() > 0) {
m_parentHandler->setBackground(files[0]);
}
}
}
void DetailsOptionsHandler::selectTextColor()
{
QColorDialog dialog(m_parentDialog);
dialog.setCurrentColor(QColor(m_ui->backPatternWidget->textColor()));
if (dialog.exec()) {
qDebug() << "layout selected text color: " << dialog.selectedColor().name();
m_parentHandler->setTextColor(dialog.selectedColor().name());
}
}
}
}
}

View File

@ -1,105 +0,0 @@
/*
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
*
* This file is part of Latte-Dock
*
* Latte-Dock 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 2 of
* the License, or (at your option) any later version.
*
* Latte-Dock 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef DETAILSINFOHANDLER_H
#define DETAILSINFOHANDLER_H
//! local
#include "generichandler.h"
#include "../data/layoutdata.h"
namespace Ui {
class DetailsDialog;
}
namespace Latte{
namespace Settings{
namespace Dialog{
class DetailsDialog;
}
}
}
namespace Latte{
namespace Settings{
namespace Handler {
class DetailsHandler;
}
}
}
namespace Latte{
namespace Settings{
namespace Model {
class Colors;
}
}
}
namespace Latte {
namespace Settings {
namespace Handler {
//! Handlers are objects to handle the UI elements that semantically associate with specific
//! ui::tabs or different windows. They are responsible also to handle the user interaction
//! between controllers and views
class DetailsOptionsHandler : public Generic
{
Q_OBJECT
public:
DetailsOptionsHandler(Dialog::DetailsDialog *parentDialog, DetailsHandler *parentHandler);
~DetailsOptionsHandler();
bool dataAreChanged() const override;
bool inDefaultValues() const override;
void reset() override;
void resetDefaults() override;
void save() override;
void selectBackground();
void selectTextColor();
private slots:
void init();
void reload();
private:
void loadLayout(const Data::Layout &data);
private:
Dialog::DetailsDialog *m_parentDialog{nullptr};
Ui::DetailsDialog *m_ui{nullptr};
DetailsHandler *m_parentHandler{nullptr};
//! current data
Model::Colors *m_colorsModel{nullptr};
QButtonGroup *m_backButtonsGroup;
};
}
}
}
#endif