mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-10 21:18:19 +03:00
viewsdialog:support vertical screens
This commit is contained in:
parent
f87fd55199
commit
f94bd35ad9
@ -241,7 +241,7 @@ void drawChangesIndicator(QPainter *painter, const QStyleOptionViewItem &option)
|
||||
|
||||
QRect remainedFromScreenDrawing(const QStyleOptionViewItem &option)
|
||||
{
|
||||
int total_length = option.rect.height() * 1.8 + MARGIN * 2;
|
||||
int total_length = option.rect.height() * 1.7 + MARGIN * 2;
|
||||
|
||||
QRect optionRemainedRect = (qApp->layoutDirection() == Qt::RightToLeft) ? QRect(option.rect.x(), option.rect.y(), option.rect.width() - total_length, option.rect.height()) :
|
||||
QRect(option.rect.x() + total_length, option.rect.y(), option.rect.width() - total_length, option.rect.height());
|
||||
@ -251,7 +251,7 @@ QRect remainedFromScreenDrawing(const QStyleOptionViewItem &option)
|
||||
|
||||
void drawScreenBackground(QPainter *painter, const QStyleOptionViewItem &option)
|
||||
{
|
||||
int total_length = option.rect.height() * 1.8 + MARGIN * 2;
|
||||
int total_length = option.rect.height() * 1.7 + MARGIN * 2;
|
||||
|
||||
QStyleOptionViewItem screenOption = option;
|
||||
screenOption.text = "";
|
||||
@ -267,17 +267,17 @@ void drawScreenBackground(QPainter *painter, const QStyleOptionViewItem &option)
|
||||
option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &screenOption, painter);
|
||||
}
|
||||
|
||||
QRect drawScreen(QPainter *painter, const QStyleOptionViewItem &option)
|
||||
QRect drawScreen(QPainter *painter, const QStyleOptionViewItem &option, bool isVertical)
|
||||
{
|
||||
int total_length = option.rect.height() * 1.8 + MARGIN * 2;
|
||||
int total_length = option.rect.height() * 1.7 + MARGIN * 2;
|
||||
int pen_width = 2;
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
//! horizontal layout scenario
|
||||
int scr_height = option.rect.height() - MARGIN * 6;
|
||||
int scr_width = 1.6 * scr_height;
|
||||
int scr_height = (!isVertical ? option.rect.height() - MARGIN * 6 : option.rect.height() - MARGIN * 4);
|
||||
int scr_width = (!isVertical ? 1.7 * scr_height : 0.8 * scr_height);
|
||||
|
||||
QRect screenMaximumRect = (qApp->layoutDirection() == Qt::RightToLeft) ?
|
||||
QRect(option.rect.x() + option.rect.width() - total_length + MARGIN, option.rect.y() + MARGIN, total_length, option.rect.height() - MARGIN*2) :
|
||||
|
@ -58,7 +58,7 @@ void drawChangesIndicator(QPainter *painter, const QStyleOptionViewItem &option)
|
||||
|
||||
//! screen icon
|
||||
QRect remainedFromScreenDrawing(const QStyleOptionViewItem &option);
|
||||
QRect drawScreen(QPainter *painter, const QStyleOptionViewItem &option); // returns screen available rect
|
||||
QRect drawScreen(QPainter *painter, const QStyleOptionViewItem &option, bool isVertical = false); // returns screen available rect
|
||||
void drawScreenBackground(QPainter *painter, const QStyleOptionViewItem &option); // returns option.rect remained rect
|
||||
void drawView(QPainter *painter, const QStyleOptionViewItem &option, const Latte::Data::View &view, const QRect &availableScreenRect);
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
// local
|
||||
#include "../viewsmodel.h"
|
||||
#include "../../generic/generictools.h"
|
||||
#include "../../../data/screendata.h"
|
||||
#include "../../../data/viewdata.h"
|
||||
|
||||
// KDE
|
||||
@ -54,6 +55,7 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
bool isActive = index.data(Model::Views::ISACTIVEROLE).toBool();
|
||||
bool isChanged = (index.data(Model::Views::ISCHANGEDROLE).toBool() || index.data(Model::Views::HASCHANGEDVIEWROLE).toBool());
|
||||
|
||||
Latte::Data::Screen screen = index.data(Model::Views::SCREENROLE).value<Latte::Data::Screen>();
|
||||
Latte::Data::View view = index.data(Model::Views::VIEWROLE).value<Latte::Data::View>();
|
||||
|
||||
if (isEmpty) {
|
||||
@ -90,10 +92,17 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
myOptions.rect = availableTextRect;
|
||||
|
||||
// draw screen icon
|
||||
bool viewisvertical{false};
|
||||
|
||||
if (!screen.geometry.isEmpty()) {
|
||||
float scrratio = screen.geometry.width() / screen.geometry.height();
|
||||
viewisvertical = (scrratio < 1.0);
|
||||
}
|
||||
|
||||
availableTextRect = Latte::remainedFromScreenDrawing(myOptions);
|
||||
|
||||
Latte::drawScreenBackground(painter, myOptions);
|
||||
QRect availableScreenRect = Latte::drawScreen(painter, myOptions);
|
||||
QRect availableScreenRect = Latte::drawScreen(painter, myOptions, viewisvertical);
|
||||
Latte::drawView(painter, myOptions, view, availableScreenRect);
|
||||
|
||||
myOptions.rect = availableTextRect;
|
||||
|
@ -208,6 +208,27 @@ bool Views::isVertical(const Plasma::Types::Location &location) const
|
||||
return (location == Plasma::Types::LeftEdge || location == Plasma::Types::RightEdge);
|
||||
}
|
||||
|
||||
Latte::Data::Screen Views::screenData(const QString &viewId) const
|
||||
{
|
||||
int row = rowForId(viewId);
|
||||
|
||||
if (row < 0) {
|
||||
return Latte::Data::Screen();
|
||||
}
|
||||
|
||||
QString primaryid = QString::number(m_corona->screenPool()->primaryScreenId());
|
||||
QString explicitid = QString::number(m_viewsTable[row].screen);
|
||||
|
||||
if (m_viewsTable[row].onPrimary && s_screens.containsId(primaryid)) {
|
||||
return s_screens[primaryid];
|
||||
} else if (!m_viewsTable[row].onPrimary && s_screens.containsId(explicitid)) {
|
||||
return s_screens[explicitid];
|
||||
}
|
||||
|
||||
return Latte::Data::Screen();
|
||||
}
|
||||
|
||||
|
||||
void Views::populateScreens()
|
||||
{
|
||||
s_screens.clear();
|
||||
@ -450,6 +471,11 @@ QVariant Views::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
} else if (role == HASCHANGEDVIEWROLE) {
|
||||
return (isNewView || (m_viewsTable[row] != o_viewsTable[origviewid]));
|
||||
} else if (role == SCREENROLE) {
|
||||
QVariant scrVariant;
|
||||
Latte::Data::Screen scrdata = screenData(m_viewsTable[row].id);
|
||||
scrVariant.setValue<Latte::Data::Screen>(scrdata);
|
||||
return scrVariant;
|
||||
} else if (role == VIEWROLE) {
|
||||
QVariant viewVariant;
|
||||
viewVariant.setValue<Latte::Data::View>(m_viewsTable[row]);
|
||||
|
@ -60,6 +60,7 @@ public:
|
||||
ISCHANGEDROLE,
|
||||
HASCHANGEDVIEWROLE,
|
||||
CHOICESROLE,
|
||||
SCREENROLE,
|
||||
VIEWROLE,
|
||||
SORTINGROLE
|
||||
};
|
||||
@ -120,6 +121,8 @@ private slots:
|
||||
private:
|
||||
bool isVertical(const Plasma::Types::Location &location) const;
|
||||
|
||||
Latte::Data::Screen screenData(const QString &viewId) const;
|
||||
|
||||
private:
|
||||
Latte::Data::ViewsTable m_viewsTable;
|
||||
Latte::Data::ViewsTable o_viewsTable;
|
||||
|
Loading…
Reference in New Issue
Block a user