create barebones window with list of streams
This commit is contained in:
+58
-3
@@ -3,18 +3,49 @@
|
||||
//
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include <QSvgWidget>
|
||||
#include <QMouseEvent>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QScreen>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
this->setAttribute(Qt::WA_AcceptTouchEvents, true);
|
||||
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
this->setFixedSize(QSize(150, 150));
|
||||
|
||||
QWidget *centralWidget = new QWidget(this);
|
||||
QVBoxLayout *layout = new QVBoxLayout(centralWidget);
|
||||
QPushButton *button = new QPushButton("Clickable Button", centralWidget);
|
||||
|
||||
QHBoxLayout *headerLayout = new QHBoxLayout(centralWidget);
|
||||
m_handleBar = new QSvgWidget(":/assets/icons/mono/basic/menu.svg", centralWidget);
|
||||
m_handleBar->setFixedSize(QSize(10, 10));
|
||||
QLabel *label = new QLabel("STREAMS", centralWidget);
|
||||
headerLayout->addWidget(m_handleBar);
|
||||
headerLayout->addWidget(label);
|
||||
|
||||
QListWidget *listWidget = new QListWidget(centralWidget);
|
||||
listWidget->addItems(QStringList{"echo-1", "beta-2", "dustin-anson", "priority-pickle"});
|
||||
|
||||
QPushButton *button = new QPushButton("+ new stream", centralWidget);
|
||||
|
||||
layout->addLayout(headerLayout);
|
||||
layout->addWidget(listWidget);
|
||||
layout->addWidget(button);
|
||||
layout->setAlignment(button, Qt::AlignCenter);
|
||||
setCentralWidget(centralWidget);
|
||||
|
||||
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.right() - this->width();
|
||||
int y = (screenSize.bottom() / 2) - (this->height() / 2);
|
||||
this->move(x, y);
|
||||
this->setCentralWidget(centralWidget);
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent *event)
|
||||
@@ -22,6 +53,30 @@ 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();
|
||||
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;
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user