1#include "DlgDesktopSize.h"
2#include "ui_DlgDesktopSize.h"
5CDlgDesktopSize::CDlgDesktopSize(QWidget *parent) :
11 m_pModel =
new QStandardItemModel(
this);
14 ui->lstSizes->setModel(m_pModel);
15 bool check = connect(m_pModel, SIGNAL(itemChanged(QStandardItem*)),
16 this, SLOT(slotItemChanged(QStandardItem*)));
21CDlgDesktopSize::~CDlgDesktopSize()
26void CDlgDesktopSize::SetDesktopSizes(
const QStringList& lstSize)
29 foreach (
auto s, lstSize) {
30 QStandardItem *item =
new QStandardItem(s);
31 m_pModel->appendRow(item);
33 m_lstDesktopSize = lstSize;
36const QStringList CDlgDesktopSize::GetDesktopSize()
38 m_lstDesktopSize.clear();
39 for(
int i = 0; i < m_pModel->rowCount(); i++)
41 QModelIndex index = m_pModel->index(i, 0);
42 QString s = m_pModel->data(index).toString();
44 m_lstDesktopSize << s;
46 return m_lstDesktopSize;
49void CDlgDesktopSize::on_pbAdd_clicked()
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);
58void CDlgDesktopSize::on_pbRemove_clicked()
60 QModelIndex index = ui->lstSizes->currentIndex();
61 m_pModel->removeRow(index.row());
64void CDlgDesktopSize::slotItemChanged(QStandardItem *item)
67 QString s = item->data(Qt::DisplayRole).toString();
74bool CDlgDesktopSize::checkFormat(QString size)
76 int index = size.indexOf(
"×");
82 int w = size.left(index).toInt(&ok);
86 int h = size.right(size.length() - index - 1).toInt(&ok);