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

mcallegari / qlcplus / 13633248611

03 Mar 2025 02:31PM UTC coverage: 31.871% (+0.4%) from 31.5%
13633248611

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 hits per line

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

0.0
/ui/src/monitor/monitorbackgroundselection.cpp
1
/*
2
  Q Light Controller Plus
3
  monitorbackgroundselection.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 <QTreeWidgetItem>
21
#include <QFileDialog>
22
#include <QSettings>
23

24
#include "monitorbackgroundselection.h"
25
#include "monitorproperties.h"
26
#include "functionselection.h"
27
#include "function.h"
28
#include "doc.h"
29

30
#define KColumnName     0
31
#define KColumnImage    1
32

33
#define SETTINGS_GEOMETRY "monitorbackgroundselection/geometry"
34

35
MonitorBackgroundSelection::MonitorBackgroundSelection(QWidget *parent, Doc *doc)
×
36
    : QDialog(parent)
37
    , m_doc(doc)
×
38
{
39
    Q_ASSERT(doc != NULL);
40
    setupUi(this);
×
41

42
    m_props = doc->monitorProperties();
×
43
    Q_ASSERT(m_props != NULL);
44

45
    m_commonBackgroundImage = m_props->commonBackgroundImage();
×
46
    m_customBackgroundImages = m_props->customBackgroundList();
×
47

48
    m_lastUsedPath = QString();
×
49

50
    QSettings settings;
×
51
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
×
52
    if (geometrySettings.isValid() == true)
×
53
        restoreGeometry(geometrySettings.toByteArray());
×
54

55
    connect(m_noBgRadio, SIGNAL(clicked(bool)),
×
56
            this, SLOT(slotNoBackgroundChecked(bool)));
57
    connect(m_commonBgRadio, SIGNAL(clicked(bool)),
×
58
            this, SLOT(slotCommonBackgroundChecked(bool)));
59
    connect(m_customBgRadio, SIGNAL(clicked(bool)),
×
60
            this, SLOT(slotCustomBackgroundChecked(bool)));
61

62
    if (m_commonBackgroundImage.isEmpty() == false)
×
63
    {
64
        m_commonBgRadio->setChecked(true);
×
65
        slotCommonBackgroundChecked(true);
×
66
    }
67
    else if (m_customBackgroundImages.isEmpty() == false)
×
68
    {
69
        m_customBgRadio->setChecked(true);
×
70
        slotCustomBackgroundChecked(true);
×
71
    }
72
    else
73
    {
74
        m_noBgRadio->setChecked(true);
×
75
        slotNoBackgroundChecked(true);
×
76
    }
77

78
    updateCustomTree();
×
79

80
    connect(m_commonButton, SIGNAL(clicked()),
×
81
            this, SLOT(slotSelectCommonBackground()));
82
    connect(m_customAddButton, SIGNAL(clicked()),
×
83
            this, SLOT(slotAddCustomBackground()));
84
    connect(m_customRemoveButton, SIGNAL(clicked()),
×
85
            this, SLOT(slotRemoveCustomBackground()));
86
}
×
87

88
MonitorBackgroundSelection::~MonitorBackgroundSelection()
×
89
{
90
    QSettings settings;
×
91
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
92
}
×
93

94
void MonitorBackgroundSelection::accept()
×
95
{
96
    m_props->setCommonBackgroundImage(QString());
×
97
    m_props->resetCustomBackgroundList();
×
98

99
    if (m_commonBgRadio->isChecked())
×
100
    {
101
        m_props->setCommonBackgroundImage(m_commonBackgroundImage);
×
102
    }
103
    else if (m_customBgRadio->isChecked())
×
104
    {
105
        m_props->setCustomBackgroundList(m_customBackgroundImages);
×
106
    }
107
    QDialog::accept();
×
108
}
×
109

110
void MonitorBackgroundSelection::updateCustomTree()
×
111
{
112
    m_customTree->clear();
×
113
    QMapIterator <quint32, QString> it(m_customBackgroundImages);
×
114
    while (it.hasNext() == true)
×
115
    {
116
        it.next();
×
117

118
        quint32 fid = it.key();
×
119
        Function *f = m_doc->function(fid);
×
120
        if (f != NULL)
×
121
        {
122
            QTreeWidgetItem *item = new QTreeWidgetItem(m_customTree);
×
123
            item->setIcon(KColumnName, f->getIcon());
×
124
            item->setText(KColumnName, f->name());
×
125
            item->setData(KColumnName, Qt::UserRole, fid);
×
126
            item->setText(KColumnImage, it.value());
×
127
        }
128
    }
129
}
×
130

131
void MonitorBackgroundSelection::slotNoBackgroundChecked(bool checked)
×
132
{
133
    if (checked == true)
×
134
    {
135
        m_commonButton->setEnabled(false);
×
136
        m_customTree->setEnabled(false);
×
137
        m_customAddButton->setEnabled(false);
×
138
        m_customRemoveButton->setEnabled(false);
×
139
    }
140
}
×
141

142
void MonitorBackgroundSelection::slotCommonBackgroundChecked(bool checked)
×
143
{
144
    if (checked == true)
×
145
    {
146
        m_commonButton->setEnabled(true);
×
147
        m_customTree->setEnabled(false);
×
148
        m_customAddButton->setEnabled(false);
×
149
        m_customRemoveButton->setEnabled(false);
×
150
    }
151
}
×
152

153
void MonitorBackgroundSelection::slotCustomBackgroundChecked(bool checked)
×
154
{
155
    if (checked == true)
×
156
    {
157
        m_commonButton->setEnabled(false);
×
158
        m_customTree->setEnabled(true);
×
159
        m_customAddButton->setEnabled(true);
×
160
        m_customRemoveButton->setEnabled(true);
×
161
    }
162
}
×
163

164
void MonitorBackgroundSelection::slotSelectCommonBackground()
×
165
{
166
    QString filename = m_props->commonBackgroundImage();
×
167

168
    filename = QFileDialog::getOpenFileName(this,
×
169
                            tr("Select background image"),
×
170
                            m_lastUsedPath,
×
171
                            QString("%1 (*.png *.bmp *.jpg *.jpeg *.gif)").arg(tr("Images")));
×
172

173
    if (filename.isEmpty() == false)
×
174
    {
175
        m_commonLabel->setText(filename);
×
176
        m_commonBackgroundImage = filename;
×
177
        m_lastUsedPath = QFileInfo(filename).canonicalPath();
×
178
    }
179
}
×
180

181
void MonitorBackgroundSelection::slotAddCustomBackground()
×
182
{
183
    FunctionSelection fs(this, m_doc);
×
184
    fs.setDisabledFunctions(m_customBackgroundImages.keys());
×
185
    fs.setMultiSelection(false);
×
186

187
    if (fs.exec() == QDialog::Accepted)
×
188
    {
189
        quint32 fid = fs.selection().first();
×
190
        QString filename = QFileDialog::getOpenFileName(this,
191
                                tr("Select background image"),
×
192
                                m_lastUsedPath,
×
193
                                QString("%1 (*.png *.bmp *.jpg *.jpeg *.gif)").arg(tr("Images")));
×
194

195
        if (filename.isEmpty() == false)
×
196
        {
197
            m_customBackgroundImages[fid] = filename;
×
198
            updateCustomTree();
×
199
            m_lastUsedPath = QFileInfo(filename).canonicalPath();
×
200
        }
201
    }
×
202
}
×
203

204
void MonitorBackgroundSelection::slotRemoveCustomBackground()
×
205
{
206
    if (m_customTree->selectedItems().isEmpty())
×
207
        return;
×
208

209
    QTreeWidgetItem *selItem = m_customTree->selectedItems().first();
×
210
    quint32 fid = selItem->data(KColumnName, Qt::UserRole).toUInt();
×
211
    m_customBackgroundImages.remove(fid);
×
212
    updateCustomTree();
×
213
}
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