chore: spike on qt widgets and ui files
This commit is contained in:
+17
-164
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user