mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 18:57:07 -07:00
Add ServerIconWidget
This commit is contained in:
parent
70b2b3f009
commit
43926a6f3f
5 changed files with 101 additions and 1 deletions
|
@ -34,7 +34,9 @@ add_executable(chiaki
|
|||
include/avopenglwidget.h
|
||||
src/avopenglwidget.cpp
|
||||
include/avopenglframeuploader.h
|
||||
src/avopenglframeuploader.cpp)
|
||||
src/avopenglframeuploader.cpp
|
||||
include/servericonwidget.h
|
||||
src/servericonwidget.cpp)
|
||||
target_include_directories(chiaki PRIVATE include)
|
||||
|
||||
target_link_libraries(chiaki chiaki-lib chiaki-cli-lib)
|
||||
|
|
41
gui/include/servericonwidget.h
Normal file
41
gui/include/servericonwidget.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_SERVERICONWIDGET_H
|
||||
#define CHIAKI_SERVERICONWIDGET_H
|
||||
|
||||
#include <chiaki/discovery.h>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class ServerIconWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
ChiakiDiscoveryHostState state = CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
public:
|
||||
explicit ServerIconWidget(QWidget *parent = nullptr) : QWidget(parent) {}
|
||||
|
||||
void SetState(ChiakiDiscoveryHostState state) { this->state = state; update(); }
|
||||
};
|
||||
|
||||
#endif // CHIAKI_SERVERICONWIDGET_H
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
class ServerIconWidget;
|
||||
|
||||
class ServerItemWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -27,6 +29,8 @@ class ServerItemWidget : public QWidget
|
|||
private:
|
||||
bool selected;
|
||||
|
||||
ServerIconWidget *icon_widget;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
|
49
gui/src/servericonwidget.cpp
Normal file
49
gui/src/servericonwidget.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 <servericonwidget.h>
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
void ServerIconWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
static const float icon_aspect = 100.0f / 17.0f;
|
||||
|
||||
if(width() == 0 || height() == 0)
|
||||
return;
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
QRect icon_rect;
|
||||
float widget_aspect = (float)width() / (float)height();
|
||||
if(widget_aspect > icon_aspect)
|
||||
{
|
||||
icon_rect.setHeight(height());
|
||||
icon_rect.setWidth((int)((float)height() * icon_aspect));
|
||||
icon_rect.moveTop(0);
|
||||
icon_rect.moveLeft((width() - icon_rect.width()) / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
icon_rect.setWidth(width());
|
||||
icon_rect.setHeight((int)((float)width() / icon_aspect));
|
||||
icon_rect.moveLeft(0);
|
||||
icon_rect.moveTop((height() - icon_rect.height()) / 2);
|
||||
}
|
||||
|
||||
painter.fillRect(icon_rect, Qt::red);
|
||||
}
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
|
||||
#include <serveritemwidget.h>
|
||||
#include <servericonwidget.h>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
@ -29,6 +30,9 @@ ServerItemWidget::ServerItemWidget(QWidget *parent) : QWidget(parent)
|
|||
auto label = new QLabel("Server", this);
|
||||
layout->addWidget(label);
|
||||
|
||||
icon_widget = new ServerIconWidget(this);
|
||||
layout->addWidget(icon_widget);
|
||||
|
||||
this->selected = true;
|
||||
SetSelected(false);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue