diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index acf07ce..a58c9e5 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -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) diff --git a/gui/include/mainwindow.h b/gui/include/mainwindow.h index 26318ed..34bbb9a 100644 --- a/gui/include/mainwindow.h +++ b/gui/include/mainwindow.h @@ -20,8 +20,8 @@ #include -class QTableWidget; class DynamicGridWidget; +class ServerItemWidget; class MainWindow : public QWidget { @@ -29,6 +29,7 @@ class MainWindow : public QWidget private: DynamicGridWidget *grid_widget; + QList server_item_widgets; public: explicit MainWindow(QWidget *parent = nullptr); diff --git a/gui/include/serveritemwidget.h b/gui/include/serveritemwidget.h new file mode 100644 index 0000000..ca5c5db --- /dev/null +++ b/gui/include/serveritemwidget.h @@ -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 . + */ + +#ifndef CHIAKI_SERVERITEMWIDGET_H +#define CHIAKI_SERVERITEMWIDGET_H + +#include + +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 diff --git a/gui/src/mainwindow.cpp b/gui/src/mainwindow.cpp index 8f07051..ce6f1b0 100644 --- a/gui/src/mainwindow.cpp +++ b/gui/src/mainwindow.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -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); } diff --git a/gui/src/serveritemwidget.cpp b/gui/src/serveritemwidget.cpp new file mode 100644 index 0000000..dab5164 --- /dev/null +++ b/gui/src/serveritemwidget.cpp @@ -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 . + */ + +#include + +#include +#include +#include + +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(); +}