mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-11-21 22:25:58 +01:00
picker: Adds elided buttons for better readability (#176)
It also fixes the region button size and alignment fixes hyprwm#175
This commit is contained in:
parent
f29e046456
commit
c06fd88b3d
5 changed files with 65 additions and 14 deletions
|
@ -17,6 +17,8 @@ set(PROJECT_SOURCES
|
||||||
mainpicker.cpp
|
mainpicker.cpp
|
||||||
mainpicker.h
|
mainpicker.h
|
||||||
mainpicker.ui
|
mainpicker.ui
|
||||||
|
elidedbutton.h
|
||||||
|
elidedbutton.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||||
|
|
31
hyprland-share-picker/elidedbutton.cpp
Normal file
31
hyprland-share-picker/elidedbutton.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include "elidedbutton.h"
|
||||||
|
|
||||||
|
ElidedButton::ElidedButton(QWidget *parent)
|
||||||
|
: QPushButton(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ElidedButton::ElidedButton( const QString& text, QWidget* parent )
|
||||||
|
: ElidedButton( parent )
|
||||||
|
{
|
||||||
|
setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElidedButton::setText(QString text)
|
||||||
|
{
|
||||||
|
og_text = text;
|
||||||
|
updateText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElidedButton::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QPushButton::resizeEvent(event);
|
||||||
|
updateText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElidedButton::updateText()
|
||||||
|
{
|
||||||
|
QFontMetrics metrics(font());
|
||||||
|
QString elided = metrics.elidedText(og_text, Qt::ElideRight, width() - 15);
|
||||||
|
QPushButton::setText(elided);
|
||||||
|
}
|
21
hyprland-share-picker/elidedbutton.h
Normal file
21
hyprland-share-picker/elidedbutton.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef ELIDEDBUTTON_H
|
||||||
|
#define ELIDEDBUTTON_H
|
||||||
|
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
class ElidedButton : public QPushButton
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ElidedButton(QWidget *parent = nullptr);
|
||||||
|
explicit ElidedButton(const QString &text, QWidget *parent = nullptr);
|
||||||
|
void setText(QString);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent *);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateText();
|
||||||
|
QString og_text;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ELIDEDBUTTON_H
|
|
@ -17,6 +17,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "mainpicker.h"
|
#include "mainpicker.h"
|
||||||
|
#include "elidedbutton.h"
|
||||||
|
|
||||||
std::string execAndGet(const char* cmd) {
|
std::string execAndGet(const char* cmd) {
|
||||||
std::array<char, 128> buffer;
|
std::array<char, 128> buffer;
|
||||||
|
@ -110,9 +111,10 @@ 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()) + " (" +
|
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()) + ") (") +
|
std::to_string(GEOMETRY.width()) + "x" + std::to_string(GEOMETRY.height()) + ") (") +
|
||||||
SCREENS[i]->name().toStdString() + ")");
|
SCREENS[i]->name().toStdString() + ")");
|
||||||
QPushButton* button = new QPushButton(text);
|
ElidedButton* button = new ElidedButton(text);
|
||||||
SCREENS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button);
|
|
||||||
button->setMinimumSize(0, BUTTON_HEIGHT);
|
button->setMinimumSize(0, BUTTON_HEIGHT);
|
||||||
|
SCREENS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button);
|
||||||
|
|
||||||
QObject::connect(button, &QPushButton::clicked, [=]() {
|
QObject::connect(button, &QPushButton::clicked, [=]() {
|
||||||
std::string ID = button->text().toStdString();
|
std::string ID = button->text().toStdString();
|
||||||
ID = ID.substr(ID.find_last_of('(') + 1);
|
ID = ID.substr(ID.find_last_of('(') + 1);
|
||||||
|
@ -147,9 +149,9 @@ int main(int argc, char* argv[]) {
|
||||||
for (auto& window : WINDOWLIST) {
|
for (auto& window : WINDOWLIST) {
|
||||||
QString text = QString::fromStdString(window.clazz + ": " + window.name);
|
QString text = QString::fromStdString(window.clazz + ": " + window.name);
|
||||||
|
|
||||||
QPushButton* button = new QPushButton(text);
|
ElidedButton* button = new ElidedButton(text);
|
||||||
WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button);
|
|
||||||
button->setMinimumSize(0, BUTTON_HEIGHT);
|
button->setMinimumSize(0, BUTTON_HEIGHT);
|
||||||
|
WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button);
|
||||||
|
|
||||||
mainPickerPtr->windowIDs[button] = window.id;
|
mainPickerPtr->windowIDs[button] = window.id;
|
||||||
|
|
||||||
|
@ -180,15 +182,10 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
QString text = "Select region...";
|
QString text = "Select region...";
|
||||||
|
|
||||||
QSpacerItem * REGION_L_SPACER = new QSpacerItem(10000,0, QSizePolicy::Expanding, QSizePolicy::Expanding);
|
ElidedButton* button = new ElidedButton(text);
|
||||||
QSpacerItem * REGION_R_SPACER = new QSpacerItem(10000,0, QSizePolicy::Expanding, QSizePolicy::Expanding);
|
button->setMaximumSize(400, BUTTON_HEIGHT);
|
||||||
|
|
||||||
REGION_LAYOUT->addItem(REGION_L_SPACER);
|
|
||||||
|
|
||||||
QPushButton* button = new QPushButton(text);
|
|
||||||
REGION_LAYOUT->addWidget(button);
|
REGION_LAYOUT->addWidget(button);
|
||||||
|
|
||||||
REGION_LAYOUT->addItem(REGION_R_SPACER);
|
|
||||||
|
|
||||||
QObject::connect(button, &QPushButton::clicked, [=]() {
|
QObject::connect(button, &QPushButton::clicked, [=]() {
|
||||||
auto REGION = execAndGet("slurp -f \"%o %x %y %w %h\"");
|
auto REGION = execAndGet("slurp -f \"%o %x %y %w %h\"");
|
||||||
|
|
|
@ -232,8 +232,8 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>730</width>
|
<width>16777215</width>
|
||||||
<height>224</height>
|
<height>16777215</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="layoutDirection">
|
<property name="layoutDirection">
|
||||||
|
@ -245,7 +245,7 @@
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Region</string>
|
<string>Region</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
<enum>QLayout::SetDefaultConstraint</enum>
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Reference in a new issue