Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
DlgDesktopSize.cpp
1#include "DlgDesktopSize.h"
2#include "ui_DlgDesktopSize.h"
3#include <QMessageBox>
4
5CDlgDesktopSize::CDlgDesktopSize(QWidget *parent) :
6 QDialog(parent),
7 ui(new Ui::CDlgDesktopSize)
8{
9 ui->setupUi(this);
10 ui->lbError->hide();
11 m_pModel = new QStandardItemModel(this);
12 if(m_pModel)
13 {
14 ui->lstSizes->setModel(m_pModel);
15 bool check = connect(m_pModel, SIGNAL(itemChanged(QStandardItem*)),
16 this, SLOT(slotItemChanged(QStandardItem*)));
17 Q_ASSERT(check);
18 }
19}
20
21CDlgDesktopSize::~CDlgDesktopSize()
22{
23 delete ui;
24}
25
26void CDlgDesktopSize::SetDesktopSizes(const QStringList& lstSize)
27{
28 m_pModel->clear();
29 foreach (auto s, lstSize) {
30 QStandardItem *item = new QStandardItem(s);
31 m_pModel->appendRow(item);
32 }
33 m_lstDesktopSize = lstSize;
34}
35
36const QStringList CDlgDesktopSize::GetDesktopSize()
37{
38 m_lstDesktopSize.clear();
39 for(int i = 0; i < m_pModel->rowCount(); i++)
40 {
41 QModelIndex index = m_pModel->index(i, 0);
42 QString s = m_pModel->data(index).toString();
43 if(checkFormat(s))
44 m_lstDesktopSize << s;
45 }
46 return m_lstDesktopSize;
47}
48
49void CDlgDesktopSize::on_pbAdd_clicked()
50{
51 QStandardItem *item = new QStandardItem("width×height");
52 m_pModel->appendRow(item);
53 QModelIndex index = m_pModel->index(m_pModel->rowCount() - 1, 0);
54 ui->lstSizes->setCurrentIndex(index);
55 ui->lstSizes->edit(index);
56}
57
58void CDlgDesktopSize::on_pbRemove_clicked()
59{
60 QModelIndex index = ui->lstSizes->currentIndex();
61 m_pModel->removeRow(index.row());
62}
63
64void CDlgDesktopSize::slotItemChanged(QStandardItem *item)
65{
66 bool ok = false;
67 QString s = item->data(Qt::DisplayRole).toString();
68 if(checkFormat(s))
69 ui->lbError->hide();
70 else
71 ui->lbError->show();
72}
73
74bool CDlgDesktopSize::checkFormat(QString size)
75{
76 int index = size.indexOf("×");
77 if(-1 == index)
78 {
79 return false;
80 }
81 bool ok = false;
82 int w = size.left(index).toInt(&ok);
83 Q_UNUSED(w);
84 if(ok)
85 {
86 int h = size.right(size.length() - index - 1).toInt(&ok);
87 Q_UNUSED(h);
88 }
89 return ok;
90}