picker: Allow dialog resizing (#173)

* picker: Allow dialog resizing

* picker: Smaller dialog and remember size changes

* picker: Save size in temp files
This commit is contained in:
rurigk 2024-01-28 06:51:53 -06:00 committed by GitHub
parent 5a59264758
commit f29e046456
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 288 additions and 156 deletions

View File

@ -7,6 +7,7 @@
#include <QWidget>
#include <QtDebug>
#include <QtWidgets>
#include <QSettings>
#include <array>
#include <cstdio>
#include <iostream>
@ -84,21 +85,24 @@ int main(int argc, char* argv[]) {
MainPicker w;
mainPickerPtr = &w;
QSettings* settings = new QSettings("/tmp/hypr/hyprland-share-picker.conf", QSettings::IniFormat);
w.setGeometry(0, 0, settings->value("width").toInt(), settings->value("height").toInt());
// get the tabwidget
const auto TABWIDGET = (QTabWidget*)w.children()[1]->children()[0];
const auto ALLOWTOKENBUTTON = (QCheckBox*)w.children()[1]->children()[1];
const auto TABWIDGET = w.findChild<QTabWidget *>("tabWidget");
const auto ALLOWTOKENBUTTON = w.findChild<QCheckBox *>("checkBox");
const auto TAB1 = (QWidget*)TABWIDGET->children()[0];
const auto SCREENS_SCROLL_AREA_CONTENTS =
(QWidget*)TAB1->findChild<QWidget*>("screens")->findChild<QScrollArea*>("scrollArea")->findChild<QWidget*>("scrollAreaWidgetContents");
const auto SCREENS_SCROLL_AREA_CONTENTS_LAYOUT = SCREENS_SCROLL_AREA_CONTENTS->layout();
// add all screens
const auto SCREENS = picker.screens();
constexpr int BUTTON_WIDTH = 441;
constexpr int BUTTON_HEIGHT = 41;
constexpr int BUTTON_PAD = 4;
for (int i = 0; i < SCREENS.size(); ++i) {
const auto GEOMETRY = SCREENS[i]->geometry();
@ -106,9 +110,9 @@ int main(int argc, char* argv[]) {
QString text = QString::fromStdString(std::string("Screen " + std::to_string(i) + " at " + std::to_string(GEOMETRY.x()) + ", " + std::to_string(GEOMETRY.y()) + " (" +
std::to_string(GEOMETRY.width()) + "x" + std::to_string(GEOMETRY.height()) + ") (") +
SCREENS[i]->name().toStdString() + ")");
QPushButton* button = new QPushButton(text, (QWidget*)SCREENS_SCROLL_AREA_CONTENTS);
button->move(9, 5 + (BUTTON_HEIGHT + BUTTON_PAD) * i);
button->resize(BUTTON_WIDTH, BUTTON_HEIGHT);
QPushButton* button = new QPushButton(text);
SCREENS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button);
button->setMinimumSize(0, BUTTON_HEIGHT);
QObject::connect(button, &QPushButton::clicked, [=]() {
std::string ID = button->text().toStdString();
ID = ID.substr(ID.find_last_of('(') + 1);
@ -119,25 +123,33 @@ int main(int argc, char* argv[]) {
std::cout << "/";
std::cout << "screen:" << ID << "\n";
settings->setValue("width", mainPickerPtr->width());
settings->setValue("height", mainPickerPtr->height());
settings->sync();
pickerPtr->quit();
return 0;
});
}
SCREENS_SCROLL_AREA_CONTENTS->resize(SCREENS_SCROLL_AREA_CONTENTS->size().width(), 5 + (BUTTON_HEIGHT + BUTTON_PAD) * SCREENS.size());
QSpacerItem * SCREENS_SPACER = new QSpacerItem(0,10000, QSizePolicy::Expanding, QSizePolicy::Expanding);
SCREENS_SCROLL_AREA_CONTENTS_LAYOUT->addItem(SCREENS_SPACER);
// windows
const auto WINDOWS_SCROLL_AREA_CONTENTS =
(QWidget*)TAB1->findChild<QWidget*>("windows")->findChild<QScrollArea*>("scrollArea_2")->findChild<QWidget*>("scrollAreaWidgetContents_2");
const auto WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT = WINDOWS_SCROLL_AREA_CONTENTS->layout();
// loop over them
int windowIterator = 0;
for (auto& window : WINDOWLIST) {
QString text = QString::fromStdString(window.clazz + ": " + window.name);
QPushButton* button = new QPushButton(text, (QWidget*)WINDOWS_SCROLL_AREA_CONTENTS);
button->move(9, 5 + (BUTTON_HEIGHT + BUTTON_PAD) * windowIterator);
button->resize(BUTTON_WIDTH, BUTTON_HEIGHT);
QPushButton* button = new QPushButton(text);
WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button);
button->setMinimumSize(0, BUTTON_HEIGHT);
mainPickerPtr->windowIDs[button] = window.id;
@ -147,6 +159,11 @@ int main(int argc, char* argv[]) {
std::cout << "/";
std::cout << "window:" << mainPickerPtr->windowIDs[button] << "\n";
settings->setValue("width", mainPickerPtr->width());
settings->setValue("height", mainPickerPtr->height());
settings->sync();
pickerPtr->quit();
return 0;
});
@ -154,16 +171,25 @@ int main(int argc, char* argv[]) {
windowIterator++;
}
WINDOWS_SCROLL_AREA_CONTENTS->resize(WINDOWS_SCROLL_AREA_CONTENTS->size().width(), 5 + (BUTTON_HEIGHT + BUTTON_PAD) * windowIterator);
QSpacerItem * WINDOWS_SPACER = new QSpacerItem(0,10000, QSizePolicy::Expanding, QSizePolicy::Expanding);
WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT->addItem(WINDOWS_SPACER);
// lastly, region
const auto REGION_OBJECT = (QWidget*)TAB1->findChild<QWidget*>("region");
const auto REGION_LAYOUT = REGION_OBJECT->layout();
QString text = "Select region...";
QPushButton* button = new QPushButton(text, (QWidget*)REGION_OBJECT);
button->move(79, 80);
button->resize(321, 41);
QSpacerItem * REGION_L_SPACER = new QSpacerItem(10000,0, QSizePolicy::Expanding, QSizePolicy::Expanding);
QSpacerItem * REGION_R_SPACER = new QSpacerItem(10000,0, QSizePolicy::Expanding, QSizePolicy::Expanding);
REGION_LAYOUT->addItem(REGION_L_SPACER);
QPushButton* button = new QPushButton(text);
REGION_LAYOUT->addWidget(button);
REGION_LAYOUT->addItem(REGION_R_SPACER);
QObject::connect(button, &QPushButton::clicked, [=]() {
auto REGION = execAndGet("slurp -f \"%o %x %y %w %h\"");
REGION = REGION.substr(0, REGION.length());
@ -206,6 +232,11 @@ int main(int argc, char* argv[]) {
std::cout << "/";
std::cout << "region:" << SCREEN_NAME << "@" << X - pScreen->geometry().x() << "," << Y - pScreen->geometry().y() << "," << W << "," << H << "\n";
settings->setValue("width", mainPickerPtr->width());
settings->setValue("height", mainPickerPtr->height());
settings->sync();
pickerPtr->quit();
return 0;
} catch (...) {

View File

@ -7,9 +7,15 @@
<x>0</x>
<y>0</y>
<width>500</width>
<height>290</height>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>500</width>
@ -18,163 +24,258 @@
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>290</height>
<width>1280</width>
<height>800</height>
</size>
</property>
<property name="windowTitle">
<string>MainPicker</string>
</property>
<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>500</width>
<height>290</height>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>290</height>
<width>1280</width>
<height>800</height>
</size>
</property>
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>290</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>500</width>
<height>290</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>290</height>
</size>
</property>
<property name="toolTip">
<string/>
</property>
<property name="tabPosition">
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="screens">
<attribute name="title">
<string>Screen</string>
</attribute>
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>9</x>
<y>9</y>
<width>461</width>
<height>201</height>
</rect>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>false</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>459</width>
<height>239</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>459</width>
<height>239</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
</property>
</widget>
</widget>
</widget>
<widget class="QWidget" name="windows">
<attribute name="title">
<string>Window</string>
</attribute>
<widget class="QScrollArea" name="scrollArea_2">
<property name="geometry">
<rect>
<x>9</x>
<y>9</y>
<width>461</width>
<height>201</height>
</rect>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>false</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>459</width>
<height>239</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>459</width>
<height>239</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
</property>
</widget>
</widget>
</widget>
<widget class="QWidget" name="region">
<attribute name="title">
<string>Region</string>
</attribute>
</widget>
</widget>
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>340</x>
<y>256</y>
<width>140</width>
<height>21</height>
</rect>
</property>
<property name="toolTip">
<string>By selecting this, the application will be given a restore token that it can use to skip prompting you next time. Only select if you trust the application.</string>
</property>
<property name="text">
<string>Allow a restore token</string>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip">
<string/>
</property>
<property name="tabPosition">
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="screens">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<attribute name="title">
<string>Screen</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>410</width>
<height>18</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<layout class="QVBoxLayout" name="screensScrollAreaLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="windows">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title">
<string>Window</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea_2">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>410</width>
<height>18</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<layout class="QVBoxLayout" name="windowsScrollAreaLayout"/>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="region">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>730</width>
<height>224</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<attribute name="title">
<string>Region</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>By selecting this, the application will be given a restore token that it can use to skip prompting you next time.
Only select if you trust the application.</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Allow a restore token</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<tabstops>
<tabstop>scrollArea</tabstop>
<tabstop>scrollArea_2</tabstop>
<tabstop>tabWidget</tabstop>
</tabstops>
<resources/>