Files
miniCashAll/libMiniCash/mcnetworkwidget.cpp

113 lines
3.3 KiB
C++
Raw Normal View History

2025-08-05 22:37:51 +02:00
/***************************************************************************
miniCash
Copyright © 2022 christoph holzheuer
c.holzheuer@sourceworx.org
This program 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.
***************************************************************************/
#include <QMessageBox>
#include <QDialog>
#include <mcnetworkwidget.h>
#include <mcnetworkdialog.h>
#include <ui_mcnetworkwidget.h>
MCNetworkWidget::MCNetworkWidget( QWidget* parent )
: QLabel{ parent }, _ui{ new Ui::MCNetworkWidget}
{
_ui->setupUi( this );
_ui->_labelState->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
/// wir haben vier mögliche Zustände
/// - das Netz wird gar nicht verwendet
/// - noch nicht verbunden
/// - Verbindungsfehler
/// - Wir haben die gewünschte Verbindung
QIcon iconOff ( miniCash::icnUnConnected );
QIcon iconOn ( miniCash::icnConnected );
QIcon iconServer( miniCash::icnServer );
_networkStates[miniCash::Disabled] = MCNetworkState( miniCash::cstDisabled, QIcon( iconOff.pixmap( QSize(64,64), QIcon::Disabled, QIcon::On ) ) );
_networkStates[miniCash::UnConnected] = MCNetworkState( miniCash::cstUnConnected, QIcon( iconOff.pixmap( QSize(64,64), QIcon::Disabled, QIcon::On ) ) );
_networkStates[miniCash::Error] = MCNetworkState( miniCash::cstError, iconOff );
_networkStates[miniCash::Connected] = MCNetworkState( miniCash::cstConnected, iconOn );
_networkStates[miniCash::IsServer] = MCNetworkState( miniCash::cstIsServer, QIcon( iconServer.pixmap( QSize(64,64), QIcon::Disabled, QIcon::On ) ) );
_networkStates[miniCash::ServerReady] = MCNetworkState( miniCash::cstServerReady, iconServer );
/// erstmal sind wir neutral
setConnectionState( miniCash::Disabled );
/// hack: Netzwerksachen sollen erst ausgeführt werden,
/// wenn das Mainwindow zu sehen ist
///QTimer::singleShot( 500, this, &MCConnectMainWindow::onStartNetworking );
/// Button nach aussen weiterleiten
connect( _ui->_buttonState, &QPushButton::clicked, this,
[=]()
{
emit showNetworkDialog();
} );
}
MCNetworkWidget::~MCNetworkWidget()
{
delete _ui;
}
miniCash::CState MCNetworkWidget::connectionState()
{
return _senderState;
}
void MCNetworkWidget::setConnectionState( miniCash::CState state )
{
qDebug() << "SET STATE:" << state;
_senderState = state;
_ui->_labelState->setText( _networkStates[_senderState].label );
_ui->_buttonState->setIcon( _networkStates[_senderState].icon );
}
/*
QPixmap pixmap = icon.pixmap(QSize(22, 22),
isEnabled() ? QIcon::Normal
: QIcon::Disabled,
isChecked() ? QIcon::On
: QIcon::Off);
myPushButton = new QPushButton();
myMovie = new QMovie("someAnimation.gif");
connect(myMovie,SIGNAL(frameChanged(int)),this,SLOT(setButtonIcon(int)));
// if movie doesn't loop forever, force it to.
if (myMovie->loopCount() != -1)
connect(myMovie,SIGNAL(finished()),myMovie,SLOT(start()));
myMovie->start();
*/