summaryrefslogtreecommitdiffstats
path: root/src/widget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widget.cpp')
-rw-r--r--src/widget.cpp103
1 files changed, 63 insertions, 40 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index 34684b5..d0f0312 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -66,10 +66,12 @@ static void addBoldListener(QComboBox *combo)
Widget::Widget(QWidget *parent) :
QWidget(parent),
_ui(new Ui::Widget),
- _popupCount(0)
+ _popupCount(0),
+ _iProjector(QIcon(":projector")),
+ _iScreen(QIcon(":screen"))
{
_ui->setupUi(this);
- setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
+ setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
QTimer *top = new QTimer(this);
connect(top, &QTimer::timeout, [=]() {
// Move window to current screen
@@ -136,29 +138,7 @@ Widget::~Widget() {
void Widget::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
- ScreenMode mode = ScreenSetup::inst()->getCurrentMode();
- if (ScreenSetup::inst()->getOutputCount() >= 2 || mode == ScreenMode::Dual) {
- if (_ui->tabWidget->widget(1) != _ui->tabDual) {
- _ui->tabWidget->insertTab(1, _ui->tabDual, tr("Dual Screen"));
- }
- } else {
- if (_ui->tabWidget->widget(1) == _ui->tabDual) {
- _ui->tabWidget->removeTab(1);
- }
- }
- switch (mode) {
- case ScreenMode::Single:
- case ScreenMode::Clone:
- _ui->tabWidget->setCurrentWidget(_ui->tabClone);
- break;
- case ScreenMode::Dual:
- _ui->tabWidget->setCurrentWidget(_ui->tabDual);
- break;
- case ScreenMode::Advanced:
- _ui->tabWidget->setCurrentWidget(_ui->tabAdvanced);
- break;
- }
- initControls();
+ initControls(true);
}
static void fillCombo(QComboBox *combo, const ResolutionVector &resolutions, const QSize &preselected, const QSize &preferred = QSize())
@@ -202,8 +182,38 @@ void Widget::comboBold(int index)
}
}
-void Widget::initControls()
+void Widget::initControls(bool jumpToTab)
{
+ //
+ ScreenMode currentOpMode = ScreenSetup::inst()->getCurrentMode();
+ _ui->tabWidget->setTabEnabled(1, CommandLine::testMode() || ScreenSetup::inst()->getOutputCount() == 2 || currentOpMode == ScreenMode::Dual);
+ QWidget *current = nullptr;
+ switch (currentOpMode) {
+ case ScreenMode::Single:
+ case ScreenMode::Clone:
+ current = _ui->tabClone;
+ break;
+ case ScreenMode::Dual:
+ current = _ui->tabDual;
+ break;
+ case ScreenMode::Advanced:
+ current = _ui->tabAdvanced;
+ break;
+ }
+ if (current != nullptr) {
+ if (jumpToTab) {
+ _ui->tabWidget->setCurrentWidget(current);
+ }
+ for (int i = 0; i < _ui->tabWidget->count(); ++i) {
+ auto w = _ui->tabWidget->widget(i);
+ if (w == current) {
+ _ui->tabWidget->setTabIcon(i, QIcon(":check"));
+ } else {
+ _ui->tabWidget->setTabIcon(i, QIcon());
+ }
+ }
+ }
+ //
if (_ui->btnDualSwap->isChecked()) {
_ui->btnDualSwap->toggle();
}
@@ -228,7 +238,7 @@ void Widget::initControls()
int j = 0;
for (int i = 0; i < screenList.size() && j < 2; ++i) {
QSize selected;
- if (ScreenSetup::inst()->getCurrentMode() == ScreenMode::Dual) {
+ if (currentOpMode == ScreenMode::Dual) {
// When we're not in dualhead mode, pre-select the preferred solution, so in case the user wants
// to switch to dualhead, they just need to switch to the "dual" tab and hit apply to get
// each screen configured to its preferred resolution.
@@ -236,8 +246,11 @@ void Widget::initControls()
}
fillCombo(lists[j], screenList[i].modes, selected, screenList[i].preferredResolution);
lists[j]->setProperty("output", screenList[i].output);
- QLabel *sl = ( j == 0 ? _ui->lblDualLeft : _ui->lblDualRight );
- sl->setText(screenList[i].output + "\n" + screenList[i].name);
+ QWidget *sl = ( j == 0 ? _ui->wDualLeft : _ui->wDualRight );
+ const QIcon &icon = screenList[i].isProjector ? _iProjector : _iScreen;
+ auto labels = sl->findChildren<QLabel*>();
+ labels[0]->setPixmap(icon.pixmap(QSize(32, 32)));
+ labels[1]->setText(screenList[i].output + "\n" + screenList[i].name);
if (screenList[i].currentResolution.isEmpty())
continue;
++j;
@@ -304,22 +317,27 @@ void Widget::initControls()
});
}
// Header
- _ui->advancedCombos->addWidget(new QLabel(tr("Output")), 0, 0);
- _ui->advancedCombos->addWidget(new QLabel(tr("Position")), 0, 2);
+ _ui->advancedCombos->addWidget(new QLabel(tr("Output")), 0, 0, 1, 2);
+ _ui->advancedCombos->addWidget(new QLabel(tr("Position")), 0, 3);
// List
int row = 1;
for (auto it = screenMap.begin(); it != screenMap.end(); ++it) {
+ int col = 0;
AdvancedOutput *a = new AdvancedOutput(it.value());
a->assignmentLabel = new QLabel(it.key(), this);
a->assignmentLabel->hide();
a->rowLabel = new QLabel(it.key());
- _ui->advancedCombos->addWidget(a->rowLabel, row, 0);
- _ui->advancedCombos->addWidget(new QLabel(a->info.name), row, 1);
+ auto ico = new QLabel();
+ const QIcon &icon = (a->info.isProjector ? _iProjector : _iScreen);
+ auto h = a->assignmentLabel->fontMetrics().height();
+ ico->setPixmap(icon.pixmap(QSize(h + 3, h)));
+ _ui->advancedCombos->addWidget(ico, row, col++);
+ _ui->advancedCombos->addWidget(a->rowLabel, row, col++);
+ _ui->advancedCombos->addWidget(new QLabel(a->info.name), row, col++);
QComboBox *cbo = new QComboBox();
a->cboPosition = cbo;
- cbo->setProperty("output", QVariant::fromValue(a));
- _ui->advancedCombos->addWidget(cbo, row, 2);
- _ui->advancedCombos->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), row, 3);
+ _ui->advancedCombos->addWidget(cbo, row, col++);
+ _ui->advancedCombos->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), row, col++);
_advancedOutput.append(a);
row++;
// Logic
@@ -327,9 +345,6 @@ void Widget::initControls()
// TODO Signal
connect(cbo, QOverload<int>::of(&QComboBox::currentIndexChanged), [a, this](int index) {
a->info.position = index - 1;
- if (a->assignmentLabel->layout() != nullptr) {
- a->assignmentLabel->layout()->removeWidget(a->cboPosition);
- }
if (index > 0) {
_advancedScreens[index - 1]->screen->layout()->addWidget(a->assignmentLabel);
a->assignmentLabel->show();
@@ -377,6 +392,14 @@ void Widget::initControls()
});
cbo->setCurrentIndex(a->info.position + 1);
}
+ // Apply Spacing
+ QLayoutItem *control;
+ int i = 0;
+ while ((control = _ui->advancedCombos->itemAt(i++)) != nullptr) {
+ if (control->widget() != nullptr) {
+ control->widget()->setStyleSheet(".QLabel {padding: 1px 7px;}");
+ }
+ }
}
bool Widget::keepResolution()
@@ -484,7 +507,7 @@ void Widget::connectButtons() {
int index = e->cboPosition->currentIndex() - 1;
if (index < 0 || index >= list.size())
continue;
- list[index].second.append(e->cboPosition->property("output").toString());
+ list[index].second.append(e->info.output);
}
if (!ScreenSetup::inst()->setCustom(list) || !keepResolution()) {
qDebug() << "reverting custom";