chore: spike on qt widgets and ui files

This commit is contained in:
talksik
2026-01-24 11:21:31 -08:00
parent 213b01b784
commit 7e1c8418c5
7 changed files with 1172 additions and 180 deletions
+17 -164
View File
@@ -3,182 +3,34 @@
//
#include "MainWindow.h"
#include <QToolButton>
#include <QSvgWidget>
#include <QMouseEvent>
#include <QPushButton>
#include <QVBoxLayout>
#include <QListWidget>
#include <QScreen>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QApplication>
#include "VerticalLabel.h"
#include "ui_mainwindow.h"
#include <QLabel>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_trayIcon(nullptr)
{
this->setAttribute(Qt::WA_TranslucentBackground, true);
this->setAttribute(Qt::WA_AcceptTouchEvents, true);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
this->resize(QSize(150, 200));
ui = new Ui::MainWindow;
ui->setupUi(this);
QWidget *widget = new QWidget(this);
ui->tabWidget->addTab(widget, "Flowy Labs, Inc");
QWidget *centralWidget = new QWidget(this);
centralWidget->setObjectName("glass");
centralWidget->setStyleSheet(R"(
#glass {
background: rgba(25, 25, 25, 0.2);
border: none;
border-radius: 0px;
}
#glass:hover {
background: rgba(25, 25, 25, 0.5);
border: none;
border-radius: 0px;
}
QLabel {
color: rgba(255, 255, 255, 0.9);
}
QToolButton {
background: transparent;
border: none;
border-radius: 4px;
padding: 4px;
}
QToolButton:hover {
background: rgba(255, 255, 255, 0.1);
}
)");
connect(ui->pushButton, &QPushButton::clicked, this, [this]() {
qDebug() << "Button clicked for signing on";
// TODO: this would make some other calls, and then
// we listen to another signal from some service/underlying model
// when auth state changes
// And then we can hide the UI or change the stackview
ui->tabWidget->setCurrentIndex(1);
QHBoxLayout *mainLayout = new QHBoxLayout(centralWidget);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
// Left sidebar - slim vertical strip
QVBoxLayout *sidebarLayout = new QVBoxLayout();
sidebarLayout->setContentsMargins(2, 4, 2, 4);
sidebarLayout->setSpacing(4);
m_handleBar = new QSvgWidget(QStringLiteral(":/assets/icons/mono/basic/menu.svg"), centralWidget);
m_handleBar->setFixedSize(QSize(16, 16));
m_handleBar->setCursor(Qt::OpenHandCursor);
// Rotated 90° "STREAMS" label
VerticalLabel *label = new VerticalLabel("STREAMS", centralWidget);
label->setStyleSheet("font-weight: bold; font-size: 10px; letter-spacing: 2px; color: rgba(255, 255, 255, 0.9);");
QToolButton *addButton = new QToolButton(centralWidget);
connect(addButton, &QToolButton::clicked, this, []() {
qDebug() << "addButtonClicked";
// we can call some other method to initialize some data whenever we are done logging in
// the complexity of this flow in qml is similar but just less imperative, more declarative
// managing the ui is technically more work, but not once we get used to it, perhaps.
});
addButton->setIcon(QIcon(QStringLiteral(":/assets/icons/mono/basic/plus.svg")));
addButton->setFixedSize(16, 16);
addButton->setIconSize(QSize(12, 12));
sidebarLayout->addWidget(m_handleBar, 0, Qt::AlignHCenter);
sidebarLayout->addWidget(label, 1, Qt::AlignHCenter);
sidebarLayout->addWidget(addButton, 0, Qt::AlignHCenter);
// Vertical separator
QFrame *separator = new QFrame(centralWidget);
separator->setStyleSheet("background-color: rgba(255, 255, 255, 0.1);");
separator->setFrameShape(QFrame::VLine);
separator->setFixedWidth(1);
// Right side with list
QVBoxLayout *contentLayout = new QVBoxLayout();
contentLayout->setContentsMargins(0, 0, 0, 0);
contentLayout->setSpacing(0);
QListWidget *listWidget = new QListWidget(centralWidget);
listWidget->addItems(QStringList{
"[j,a] what are we going to...",
"[p] going to it",
"[p, f] change the ui",
"[d,j,k] drop off the money",
});
listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QListWidgetItem *item = new QListWidgetItem(listWidget);
item->setCheckState(Qt::Checked);
item->setText("do this");
listWidget->setStyleSheet(R"(
QListWidget {
background: transparent;
border: none;
color: white;
font-size: 14px;
outline: none;
}
QListWidget::item {
padding: 2px;
border-radius: 0px;
margin: 2px 0px;
}
QListWidget::item:hover {
background: rgba(255, 255, 255, 0.1);
}
QListWidget::item:selected {
background: rgba(255, 255, 255, 0.15);
}
)");
listWidget->viewport()->setStyleSheet("background: transparent;");
QLabel *actionLabel = new QLabel("Hold space");
actionLabel->setStyleSheet("color: lightgrey;");
actionLabel->setAlignment(Qt::AlignHCenter);
contentLayout->addWidget(listWidget);
contentLayout->addWidget(actionLabel);
mainLayout->addLayout(sidebarLayout);
mainLayout->addWidget(separator);
mainLayout->addLayout(contentLayout, 1);
const QScreen *screen = QGuiApplication::primaryScreen();
const QRect screenSize = screen->geometry();
qDebug() << "Width of window: " << this->width();
qDebug() << "Height of window: " << this->height();
int x = screenSize.left();
int y = (screenSize.bottom() / 2) - (this->height() / 2);
this->move(x, y);
this->setCentralWidget(centralWidget);
setupTrayIcon();
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
QMainWindow::resizeEvent(event); // Let layout finish first
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && m_handleBar->geometry().contains(event->pos()))
{
dragging = true;
dragPosition = event->globalPosition().toPoint() - frameGeometry().topLeft();
setCursor(Qt::ClosedHandCursor);
event->accept();
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if (dragging && (event->buttons() & Qt::LeftButton))
{
move(event->globalPosition().toPoint() - dragPosition);
event->accept();
}
}
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
dragging = false;
unsetCursor();
}
void MainWindow::setupTrayIcon()
{
m_trayIcon = new QSystemTrayIcon(this);
@@ -201,4 +53,5 @@ void MainWindow::setupTrayIcon()
MainWindow::~MainWindow()
{
delete ui;
}
+6 -14
View File
@@ -8,10 +8,13 @@
#include <QMainWindow>
QT_BEGIN_NAMESPACE
class QSvgWidget;
class QSystemTrayIcon;
QT_END_NAMESPACE
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -21,22 +24,11 @@ public:
~MainWindow();
protected:
void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
private:
void setupTrayIcon();
QSvgWidget *m_handleBar;
QSystemTrayIcon *m_trayIcon;
QPoint dragPosition;
bool dragging = false;
Ui::MainWindow *ui;
};
#endif //LLINK_MAINWINDOW_H
#endif //LLINK_MAINWINDOW_H
+146
View File
@@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>598</height>
</rect>
</property>
<property name="windowTitle">
<string>Flowy.llink</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>801</width>
<height>541</height>
</rect>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_1">
<attribute name="title">
<string>Sign in</string>
</attribute>
<widget class="QFrame" name="frame">
<property name="geometry">
<rect>
<x>250</x>
<y>150</y>
<width>291</width>
<height>151</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>251</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2">
<property name="geometry">
<rect>
<x>20</x>
<y>80</y>
<width>71</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Email</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>58</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Code</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>20</x>
<y>110</y>
<width>101</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Continue</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>App</string>
</attribute>
<widget class="QCalendarWidget" name="calendarWidget">
<property name="geometry">
<rect>
<x>110</x>
<y>40</y>
<width>551</width>
<height>401</height>
</rect>
</property>
</widget>
</widget>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>