mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 18:57:07 -07:00
Add Basic ServerItemWidget
This commit is contained in:
parent
0e547f1540
commit
264d7523ec
5 changed files with 102 additions and 6 deletions
|
@ -18,7 +18,9 @@ add_executable(chiaki
|
|||
include/mainwindow.h
|
||||
src/mainwindow.cpp
|
||||
include/dynamicgridwidget.h
|
||||
src/dynamicgridwidget.cpp)
|
||||
src/dynamicgridwidget.cpp
|
||||
include/serveritemwidget.h
|
||||
src/serveritemwidget.cpp)
|
||||
target_include_directories(chiaki PRIVATE include)
|
||||
|
||||
target_link_libraries(chiaki chiaki-lib)
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
class QTableWidget;
|
||||
class DynamicGridWidget;
|
||||
class ServerItemWidget;
|
||||
|
||||
class MainWindow : public QWidget
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ class MainWindow : public QWidget
|
|||
|
||||
private:
|
||||
DynamicGridWidget *grid_widget;
|
||||
QList<ServerItemWidget *> server_item_widgets;
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
|
|
41
gui/include/serveritemwidget.h
Normal file
41
gui/include/serveritemwidget.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CHIAKI_SERVERITEMWIDGET_H
|
||||
#define CHIAKI_SERVERITEMWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class ServerItemWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
bool selected;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
public:
|
||||
explicit ServerItemWidget(QWidget *parent = nullptr);
|
||||
|
||||
bool IsSelected() { return selected; }
|
||||
void SetSelected(bool selected);
|
||||
};
|
||||
|
||||
#endif //CHIAKI_CONSOLEITEMWIDGET_H
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <mainwindow.h>
|
||||
#include <dynamicgridwidget.h>
|
||||
#include <serveritemwidget.h>
|
||||
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
@ -37,16 +38,14 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
|
|||
scroll_content_widget->setLayout(scroll_content_layout);
|
||||
scroll_area->setWidget(scroll_content_widget);
|
||||
|
||||
grid_widget = new DynamicGridWidget(100, scroll_content_widget);
|
||||
grid_widget = new DynamicGridWidget(200, scroll_content_widget);
|
||||
scroll_content_layout->addWidget(grid_widget);
|
||||
scroll_content_layout->addStretch(0);
|
||||
grid_widget->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
QWidget *w = new QWidget(grid_widget);
|
||||
w->setFixedSize(100, 100);
|
||||
w->setStyleSheet("background-color: red;");
|
||||
auto w = new ServerItemWidget(grid_widget);
|
||||
grid_widget->AddWidget(w);
|
||||
}
|
||||
|
||||
|
|
53
gui/src/serveritemwidget.cpp
Normal file
53
gui/src/serveritemwidget.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <serveritemwidget.h>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QStyle>
|
||||
|
||||
ServerItemWidget::ServerItemWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
auto layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
auto label = new QLabel("Server", this);
|
||||
layout->addWidget(label);
|
||||
|
||||
SetSelected(false);
|
||||
|
||||
setFixedSize(200, 200);
|
||||
}
|
||||
|
||||
void ServerItemWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
SetSelected(!IsSelected());
|
||||
}
|
||||
|
||||
void ServerItemWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerItemWidget::SetSelected(bool selected)
|
||||
{
|
||||
if(this->selected == selected)
|
||||
return;
|
||||
this->selected = selected;
|
||||
setStyleSheet(selected ? "background-color: palette(highlight);" : "");
|
||||
update();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue