1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-10 21:18:19 +03:00

viewsdialog:draw screen with real screen factor

This commit is contained in:
Michail Vourlakos 2021-04-11 11:22:25 +03:00
parent 00a1fc05ef
commit 2a85a7afae
3 changed files with 8 additions and 13 deletions

View File

@ -279,8 +279,11 @@ void drawScreenBackground(QPainter *painter, const QStyleOptionViewItem &option)
option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &screenOption, painter);
}
QRect drawScreen(QPainter *painter, const QStyleOptionViewItem &option, bool isVertical)
QRect drawScreen(QPainter *painter, const QStyleOptionViewItem &option, QRect screenGeometry)
{
float scr_ratio = (float)screenGeometry.width() / (float)screenGeometry.height();
bool isVertical = (scr_ratio < 1.0);
int scr_maxlength = screenMaxLength(option);
int scr_maxthickness = option.rect.height() - MARGIN * 2;
@ -290,9 +293,9 @@ QRect drawScreen(QPainter *painter, const QStyleOptionViewItem &option, bool isV
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
//! horizontal layout scenario
scr_ratio = qMin(qMax((float)0.75, scr_ratio), (float)1.7);
int scr_height = (!isVertical ? option.rect.height() - MARGIN * 6 : option.rect.height() - MARGIN * 4);
int scr_width = (!isVertical ? scr_height * 1.6 : 0.8 * scr_height);
int scr_width = scr_ratio * scr_height;
//! provide even screen width and height
if (scr_width % 2 == 1) {

View File

@ -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, bool isVertical = false); // returns screen available rect
QRect drawScreen(QPainter *painter, const QStyleOptionViewItem &option, QRect screenGeometry); // 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);

View File

@ -91,18 +91,10 @@ 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, viewisvertical);
QRect availableScreenRect = Latte::drawScreen(painter, myOptions, screen.geometry);
Latte::drawView(painter, myOptions, view, availableScreenRect);
myOptions.rect = availableTextRect;