• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mcallegari / qlcplus / 8961243534

05 May 2024 09:23PM UTC coverage: 32.068% (+4.0%) from 28.094%
8961243534

push

github

mcallegari
Merge branch 'master' into qmltoqt6

902 of 2557 new or added lines in 140 files covered. (35.28%)

166 existing lines in 76 files now uncovered.

15395 of 48008 relevant lines covered (32.07%)

22949.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/ui/src/universeitemwidget.cpp
1
/*
2
  Q Light Controller Plus
3
  universeitemwidget.cpp
4

5
  Copyright (c) Massimo Callegari
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include <QApplication>
21
#include <QWidget>
22
#include <QFont>
23
#include <QDebug>
24

25
#include "universeitemwidget.h"
26

27
UniverseItemWidget::UniverseItemWidget(QWidget *parent)
×
28
    : QItemDelegate(parent)
×
29
{
NEW
30
    setClipping(false);
×
31
}
×
32

33
UniverseItemWidget::~UniverseItemWidget()
×
34
{
35
}
×
36

37
void UniverseItemWidget::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
×
38
{
NEW
39
    QWidget *list = qobject_cast<QWidget *>(parent());
×
NEW
40
    qreal pWidth = list->geometry().width();
×
41
    QRect r = option.rect;
×
42
    QFont font = qApp->font();
×
43
    font.setBold(true);
×
44
    font.setPixelSize(18);
×
45
    painter->setRenderHint(QPainter::Antialiasing, true);
×
46

47
    // draw background gradient
48
    QLinearGradient linearGrad(r.left(), r.top(), r.left(), r.height() + r.top());
×
49

NEW
50
    if (option.state & QStyle::State_Selected)
×
51
    {
52
        linearGrad.setColorAt(0, QColor(50, 64, 75, 255));
×
53
        linearGrad.setColorAt(1, QColor(76, 98, 115, 255));
×
54
        painter->setPen(QPen(QColor(48, 61, 72, 255), 2));
×
55
    }
56
    else
57
    {
58
        linearGrad.setColorAt(0, QColor(255, 255, 255, 255));
×
59
        linearGrad.setColorAt(1, QColor(128, 128, 128, 255));
×
60
        painter->setPen(QPen(QColor(30, 30, 30, 255), 2));
×
61
    }
62
    painter->setBrush(linearGrad);
×
NEW
63
    painter->drawRoundedRect(r.left() + 2, r.top() + 2, pWidth - 6, r.height() - 4, 5, 5);
×
64

NEW
65
    if (option.state & QStyle::State_Selected)
×
66
        painter->setPen(QPen(QColor(200, 200, 200, 255), 2));
×
67
    else
68
        painter->setPen(QPen(QColor(0, 0, 0, 255), 2));
×
69

70
    // draw universe name
71
    painter->setFont(font);
×
72
    painter->drawText(QRect(10, r.top() + 5, 150, r.height() - 10),
×
73
                      Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter, index.data(Qt::DisplayRole).toString());
×
74

75
    font.setPixelSize(12);
×
76
    painter->setFont(font);
×
77

78
    QVariant var = index.data(Qt::DecorationRole);
×
79
    if (var.isValid())
×
80
    {
81
        QIcon icon = var.value<QIcon>();
×
82
        if (icon.isNull() == false)
×
NEW
83
            painter->drawPixmap(pWidth - 36, r.top() + 9, 32, 32, icon.pixmap(32, 32));
×
84
    }
85

86
    // draw input output labels
NEW
87
    int midPos = (pWidth - 10 - 150) / 2;
×
88
    midPos += 170;
×
89
    QString inStr = tr("Input:");
×
90
    QString proStr = tr("Profile:");
×
91
    QString outStr = tr("Output:");
×
92
    QString fbStr = tr("Feedback:");
×
93
    painter->drawText(QRect(170, r.top() + 10, 150, 20), Qt::AlignLeft, inStr);
×
94
    painter->drawText(QRect(midPos, r.top() + 10, 150, 20), Qt::AlignLeft, proStr);
×
95
    painter->drawText(QRect(170, r.top() + 30, 150, 20), Qt::AlignLeft, outStr);
×
96
    painter->drawText(QRect(midPos, r.top() + 30, 150, 20), Qt::AlignLeft, fbStr);
×
97

98
    QFontMetrics fm(font);
×
99
#if (QT_VERSION < QT_VERSION_CHECK(5, 11, 0))
100
    int inPos = fm.width(inStr) + 170 + 5;
101
    int proPos = fm.width(proStr) + midPos + 5;
102
    int outPos = fm.width(outStr) + 170 + 5;
103
    int fbPos = fm.width(fbStr) + midPos + 5;
104
#else
105
    int inPos = fm.horizontalAdvance(inStr) + 170 + 5;
×
106
    int proPos = fm.horizontalAdvance(proStr) + midPos + 5;
×
107
    int outPos = fm.horizontalAdvance(outStr) + 170 + 5;
×
108
    int fbPos = fm.horizontalAdvance(fbStr) + midPos + 5;
×
109
#endif
110
    font.setBold(false);
×
111
    painter->setFont(font);
×
112

113
    // draw input output plugin/profile names
114
    QString inputName = index.data(Qt::UserRole + 1).toString();
×
115
    if (inputName == "None") inputName = tr("None");
×
116
    QString profileName = index.data(Qt::UserRole + 2).toString();
×
117
    if (profileName == "None") profileName = tr("None");
×
118
    QString outputName = index.data(Qt::UserRole + 3).toString();
×
119
    if (outputName == "None") outputName = tr("None");
×
120
    QString fbName = index.data(Qt::UserRole + 4).toString();
×
121
    if (fbName == "None") fbName = tr("None");
×
122

123
    painter->drawText(QRect(inPos, r.top() + 10, midPos - inPos, 20),
×
124
                      Qt::AlignLeft, inputName);
NEW
125
    painter->drawText(QRect(proPos, r.top() + 10, pWidth - proPos, 20),
×
126
                      Qt::AlignLeft, profileName);
127
    painter->drawText(QRect(outPos, r.top() + 30, midPos - outPos, 20),
×
128
                      Qt::AlignLeft, outputName);
NEW
129
    painter->drawText(QRect(fbPos, r.top() + 30, pWidth - fbPos, 20),
×
130
                      Qt::AlignLeft, fbName);
131
}
×
132

133

134

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc