mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-11 13:18:13 +03:00
provide custom layout combobox
--custom layout combobox provides also the chosen drawn layout icon
This commit is contained in:
parent
7bfb23fa45
commit
d903da90e7
@ -483,7 +483,7 @@
|
||||
<item row="1" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
||||
<item>
|
||||
<widget class="QComboBox" name="layoutsCmb">
|
||||
<widget class="Latte::Settings::LayoutsComboBox" name="layoutsCmb">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>358</width>
|
||||
@ -581,6 +581,11 @@
|
||||
<header>settings/detailsdialog/patternwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Latte::Settings::LayoutsComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>settings/generic/layoutscombobox.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
@ -137,7 +137,10 @@ void DetailsHandler::reload()
|
||||
o_data = m_dialog->layoutsController()->selectedLayoutCurrentData();
|
||||
c_data = o_data;
|
||||
|
||||
Latte::Data::LayoutIcon icon = m_dialog->layoutsController()->selectedLayoutIcon();
|
||||
|
||||
m_ui->layoutsCmb->setCurrentText(o_data.name);
|
||||
m_ui->layoutsCmb->setLayoutIcon(icon);
|
||||
|
||||
loadLayout(c_data);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ set(lattedock-app_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/genericdialog.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/generichandler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/generictools.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/layoutscombobox.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/persistentmenu.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
@ -27,7 +27,7 @@ namespace Latte {
|
||||
|
||||
const int MARGIN = 1;
|
||||
|
||||
bool isEnabled(const QStyleOptionViewItem &option)
|
||||
bool isEnabled(const QStyleOption &option)
|
||||
{
|
||||
if (option.state & QStyle::State_Enabled) {
|
||||
return true;
|
||||
@ -36,7 +36,7 @@ bool isEnabled(const QStyleOptionViewItem &option)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isActive(const QStyleOptionViewItem &option)
|
||||
bool isActive(const QStyleOption &option)
|
||||
{
|
||||
if (option.state & QStyle::State_Active) {
|
||||
return true;
|
||||
@ -45,7 +45,7 @@ bool isActive(const QStyleOptionViewItem &option)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isSelected(const QStyleOptionViewItem &option)
|
||||
bool isSelected(const QStyleOption &option)
|
||||
{
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
return true;
|
||||
@ -54,7 +54,7 @@ bool isSelected(const QStyleOptionViewItem &option)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isHovered(const QStyleOptionViewItem &option)
|
||||
bool isHovered(const QStyleOption &option)
|
||||
{
|
||||
if (option.state & QStyle::State_MouseOver) {
|
||||
return true;
|
||||
@ -63,7 +63,7 @@ bool isHovered(const QStyleOptionViewItem &option)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isFocused(const QStyleOptionViewItem &option)
|
||||
bool isFocused(const QStyleOption &option)
|
||||
{
|
||||
if (option.state & QStyle::State_HasFocus) {
|
||||
return true;
|
||||
@ -72,7 +72,7 @@ bool isFocused(const QStyleOptionViewItem &option)
|
||||
return false;
|
||||
}
|
||||
|
||||
QPalette::ColorGroup colorGroup(const QStyleOptionViewItem &option)
|
||||
QPalette::ColorGroup colorGroup(const QStyleOption &option)
|
||||
{
|
||||
if (!isEnabled(option)) {
|
||||
return QPalette::Disabled;
|
||||
@ -102,7 +102,7 @@ QStringList subtracted(const QStringList &original, const QStringList ¤t)
|
||||
return subtract;
|
||||
}
|
||||
|
||||
void drawLayoutIcon(QPainter *painter, const QStyleOptionViewItem &option, const QRect &target, const Latte::Data::LayoutIcon &icon)
|
||||
void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const QRect &target, const Latte::Data::LayoutIcon &icon)
|
||||
{
|
||||
bool active = Latte::isActive(option);
|
||||
bool selected = Latte::isSelected(option);
|
||||
|
@ -28,23 +28,23 @@
|
||||
#include <QPainter>
|
||||
#include <QPalette>
|
||||
#include <QRect>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include <QStyleOption>
|
||||
|
||||
namespace Latte {
|
||||
|
||||
bool isActive(const QStyleOptionViewItem &option);
|
||||
bool isEnabled(const QStyleOptionViewItem &option);
|
||||
bool isFocused(const QStyleOptionViewItem &option);
|
||||
bool isSelected(const QStyleOptionViewItem &option);
|
||||
bool isHovered(const QStyleOptionViewItem &option);
|
||||
bool isActive(const QStyleOption &option);
|
||||
bool isEnabled(const QStyleOption &option);
|
||||
bool isFocused(const QStyleOption &option);
|
||||
bool isSelected(const QStyleOption &option);
|
||||
bool isHovered(const QStyleOption &option);
|
||||
|
||||
QPalette::ColorGroup colorGroup(const QStyleOptionViewItem &option);
|
||||
QPalette::ColorGroup colorGroup(const QStyleOption &option);
|
||||
|
||||
//! strings that even though they were initially at original list
|
||||
//! now they are not present to current list
|
||||
QStringList subtracted(const QStringList &original, const QStringList ¤t);
|
||||
|
||||
void drawLayoutIcon(QPainter *painter, const QStyleOptionViewItem &option, const QRect &target, const Latte::Data::LayoutIcon &icon);
|
||||
void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const QRect &target, const Latte::Data::LayoutIcon &icon);
|
||||
|
||||
}
|
||||
|
||||
|
84
app/settings/generic/layoutscombobox.cpp
Normal file
84
app/settings/generic/layoutscombobox.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2021 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 "layoutscombobox.h"
|
||||
|
||||
// local
|
||||
#include "generictools.h"
|
||||
|
||||
// Qt
|
||||
#include <QDebug>
|
||||
#include <QPalette>
|
||||
#include <QStyleOptionComboBox>
|
||||
#include <QStylePainter>
|
||||
|
||||
namespace Latte {
|
||||
namespace Settings {
|
||||
|
||||
const int MARGIN = 4;
|
||||
const int VERTMARGIN = 4;
|
||||
|
||||
LayoutsComboBox::LayoutsComboBox(QWidget *parent)
|
||||
: QComboBox (parent)
|
||||
{
|
||||
}
|
||||
|
||||
Latte::Data::LayoutIcon LayoutsComboBox::layoutIcon() const
|
||||
{
|
||||
return m_layoutIcon;
|
||||
}
|
||||
|
||||
void LayoutsComboBox::setLayoutIcon(const Latte::Data::LayoutIcon &icon)
|
||||
{
|
||||
if (m_layoutIcon == icon) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_layoutIcon = icon;
|
||||
update();
|
||||
}
|
||||
|
||||
void LayoutsComboBox::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QStylePainter painter(this);
|
||||
painter.setPen(palette().color(QPalette::Text));
|
||||
|
||||
// draw the combobox frame, focusrect and selected etc.
|
||||
QStyleOptionComboBox opt;
|
||||
initStyleOption(&opt);
|
||||
painter.drawComplexControl(QStyle::CC_ComboBox, opt);
|
||||
|
||||
//! Adjust text and layout icon accordingly
|
||||
int thick = opt.rect.height() - 2 * VERTMARGIN;
|
||||
int textX = opt.rect.x() + thick + 1;
|
||||
QRect textRect(textX, opt.rect.y(), opt.rect.width() - thick - 1, opt.rect.height());
|
||||
|
||||
QStyleOptionComboBox adjOpt = opt;
|
||||
adjOpt.rect = textRect;
|
||||
// draw text
|
||||
painter.drawControl(QStyle::CE_ComboBoxLabel, adjOpt);
|
||||
|
||||
QRect iconRect(opt.rect.x() + MARGIN, opt.rect.y() + VERTMARGIN, thick, thick);
|
||||
// draw layout icon
|
||||
Latte::drawLayoutIcon(&painter, opt, iconRect, m_layoutIcon);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
53
app/settings/generic/layoutscombobox.h
Normal file
53
app/settings/generic/layoutscombobox.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2021 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 LAYOUTSCOMBOBOX_H
|
||||
#define LAYOUTSCOMBOBOX_H
|
||||
|
||||
//local
|
||||
#include "../../data/layouticondata.h"
|
||||
|
||||
//Qt
|
||||
#include <QComboBox>
|
||||
#include <QPaintEvent>
|
||||
|
||||
namespace Latte {
|
||||
namespace Settings {
|
||||
|
||||
class LayoutsComboBox : public QComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LayoutsComboBox(QWidget *parent = nullptr);
|
||||
|
||||
Latte::Data::LayoutIcon layoutIcon() const;
|
||||
void setLayoutIcon(const Latte::Data::LayoutIcon &icon);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
Latte::Data::LayoutIcon m_layoutIcon;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -240,6 +240,19 @@ void Layouts::initializeSelectedLayoutViews()
|
||||
}
|
||||
}
|
||||
|
||||
const Latte::Data::LayoutIcon Layouts::selectedLayoutIcon() const
|
||||
{
|
||||
int selectedRow = m_view->currentIndex().row();
|
||||
|
||||
if (selectedRow >= 0) {
|
||||
QString selectedId = m_proxyModel->data(m_proxyModel->index(selectedRow, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
|
||||
return m_model->currentLayoutIcon(selectedId);
|
||||
}
|
||||
|
||||
return Latte::Data::LayoutIcon();
|
||||
|
||||
}
|
||||
|
||||
const Latte::Data::Layout Layouts::selectedLayoutCurrentData() const
|
||||
{
|
||||
int selectedRow = m_view->currentIndex().row();
|
||||
@ -256,7 +269,7 @@ const Latte::Data::Layout Layouts::selectedLayoutOriginalData() const
|
||||
int selectedRow = m_view->currentIndex().row();
|
||||
QString selectedId = m_proxyModel->data(m_proxyModel->index(selectedRow, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
|
||||
|
||||
return m_model->originalData(selectedId);;
|
||||
return m_model->originalData(selectedId);
|
||||
}
|
||||
|
||||
bool Layouts::inMultipleMode() const
|
||||
|
@ -75,6 +75,7 @@ public:
|
||||
bool hasSelectedLayout() const;
|
||||
const Latte::Data::Layout selectedLayoutCurrentData() const;
|
||||
const Latte::Data::Layout selectedLayoutOriginalData() const;
|
||||
const Latte::Data::LayoutIcon selectedLayoutIcon() const;
|
||||
|
||||
void selectRow(const QString &id);
|
||||
void setLayoutProperties(const Latte::Data::Layout &layout);
|
||||
|
@ -474,6 +474,18 @@ QList<Latte::Data::LayoutIcon> Layouts::icons(const int &row) const
|
||||
return iconsForCentralLayout(row);
|
||||
}
|
||||
|
||||
const Latte::Data::LayoutIcon Layouts::currentLayoutIcon(const QString &id) const
|
||||
{
|
||||
int row = rowForId(id);
|
||||
QList<Latte::Data::LayoutIcon> iconsList;
|
||||
|
||||
if (row >= 0) {
|
||||
iconsList = icons(row);
|
||||
}
|
||||
|
||||
return iconsList.count() > 0 ? iconsList[0] : Latte::Data::LayoutIcon();
|
||||
}
|
||||
|
||||
QString Layouts::sortableText(const int &priority, const int &row) const
|
||||
{
|
||||
QString numberPart;
|
||||
|
@ -118,6 +118,8 @@ public:
|
||||
|
||||
int rowForId(const QString &id) const;
|
||||
|
||||
const Latte::Data::LayoutIcon currentLayoutIcon(const QString &id) const;
|
||||
|
||||
void clear();
|
||||
//! all current data will become also original
|
||||
void applyData();
|
||||
|
@ -49,7 +49,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="layoutsCmb">
|
||||
<widget class="Latte::Settings::LayoutsComboBox" name="layoutsCmb">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@ -242,6 +242,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Latte::Settings::LayoutsComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>settings/generic/layoutscombobox.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
@ -83,7 +83,12 @@ void ViewsHandler::reload()
|
||||
|
||||
o_data = m_dialog->layoutsController()->selectedLayoutCurrentData();
|
||||
c_data = o_data;
|
||||
|
||||
Latte::Data::LayoutIcon icon = m_dialog->layoutsController()->selectedLayoutIcon();
|
||||
|
||||
m_ui->layoutsCmb->setCurrentText(o_data.name);
|
||||
m_ui->layoutsCmb->setLayoutIcon(icon);
|
||||
|
||||
loadLayout(c_data);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user