Skip to content

Commit

Permalink
ScopyStatusBar: added MenuAnim and StatusMessage to status bar
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei-Fabian-Pop <[email protected]>
  • Loading branch information
Andrei-Fabian-Pop committed Oct 17, 2023
1 parent b803ccb commit eaf2ec2
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 206 deletions.
4 changes: 2 additions & 2 deletions core/include/core/scopymainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "iioutil/cyclicaltask.h"
#include "iioutil/iioscantask.h"
#include <gui/widgets/scopystatusbar.h>
#include "versioncheckoverlay.h"
#include "versioncheckmessage.h"

QT_BEGIN_NAMESPACE
namespace Ui {
Expand Down Expand Up @@ -67,7 +67,7 @@ public Q_SLOTS:
DetachedToolWindowManager *dtm;

LicenseOverlay *license = nullptr;
VersionCheckOverlay *checkUpdate = nullptr;
VersionCheckMessage *checkUpdate = nullptr;
ScopyStatusBar *statusBar;
ScopyMainWindow_API *api;
Ui::ScopyMainWindow *ui;
Expand Down
26 changes: 26 additions & 0 deletions core/include/core/versioncheckmessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef SCOPY_VERSIONCHECKMESSAGE_H
#define SCOPY_VERSIONCHECKMESSAGE_H

#include <QPushButton>
#include <QWidget>

#include <popupwidget.h>

namespace scopy {
class VersionCheckMessage : public QWidget
{
Q_OBJECT

public:
explicit VersionCheckMessage(QWidget *parent = nullptr);
~VersionCheckMessage();

Q_SIGNALS:
void setCheckVersion(bool allowed);

private Q_SLOTS:
void saveCheckVersion(bool allowed);
};
} // namespace scopy

#endif // SCOPY_VERSIONCHECKMESSAGE_H
21 changes: 0 additions & 21 deletions core/include/core/versioncheckoverlay.h

This file was deleted.

3 changes: 3 additions & 0 deletions core/src/devicemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "deviceimpl.h"
#include "deviceloader.h"
#include "iiodeviceimpl.h"
#include "pluginbase/statusmanager.h"

#include <QDebug>
#include <QLoggingCategory>
Expand Down Expand Up @@ -176,6 +177,7 @@ void DeviceManager::connectDevice(QString id)
}

connectedDev.append(id);
StatusManager::GetInstance()->addTemporaryMessage("Connected to " + map[id]->id(), 3000);
Q_EMIT deviceConnected(id, map[id]);
}

Expand All @@ -189,6 +191,7 @@ void DeviceManager::disconnectDevice(QString id)
{
qDebug(CAT_DEVICEMANAGER) << "disconnecting " << id << "...";
connectedDev.removeOne(id);
StatusManager::GetInstance()->addTemporaryMessage("Disconnected from " + map[id]->id(), 3000);
Q_EMIT requestTool("home");
Q_EMIT deviceDisconnected(id, map[id]);
}
Expand Down
44 changes: 35 additions & 9 deletions core/src/scopymainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <utility>
#include <stylehelper.h>
#include <scopymainwindow_api.h>
#include <QVersionNumber>

using namespace scopy;

Expand All @@ -49,6 +50,7 @@ ScopyMainWindow::ScopyMainWindow(QWidget *parent)
StyleHelper::GetInstance()->initColorMap();
setAttribute(Qt::WA_QuitOnClose, true);
initPythonWIN32();
initStatusBar();
initPreferences();

ContextProvider::GetInstance();
Expand Down Expand Up @@ -156,11 +158,6 @@ ScopyMainWindow::ScopyMainWindow(QWidget *parent)
void ScopyMainWindow::initStatusBar()
{
// clear all margin, except the bottom one, to make room the status bar
int margin = ui->centralwidget->layout()->margin();
ui->centralwidget->layout()->setMargin(0);
ui->centralwidget->setContentsMargins(margin, margin, margin, 0);
ui->animHolder->setContentsMargins(0, 0, 0, margin); // the left panel should keep the margin

statusBar = new ScopyStatusBar(this);
ui->mainWidget->layout()->addWidget(statusBar);
}
Expand Down Expand Up @@ -274,13 +271,15 @@ void ScopyMainWindow::initPreferences()
loadDecoders();
}
if(p->get("general_show_status_bar").toBool()) {
initStatusBar();
StatusManager::GetInstance()->setEnabled(true);
}
if(p->get("general_first_run").toBool()) {
license = new LicenseOverlay(this);
checkUpdate = new VersionCheckOverlay(this);
auto versionCheckInfo = new VersionCheckMessage(this);

StatusManager::GetInstance()->addTemporaryWidget(versionCheckInfo,
"Should Scopy check for online versions?");

QMetaObject::invokeMethod(checkUpdate, &VersionCheckOverlay::showOverlay, Qt::QueuedConnection);
QMetaObject::invokeMethod(license, &LicenseOverlay::showOverlay, Qt::QueuedConnection);
}
QString theme = p->get("general_theme").toString();
Expand Down Expand Up @@ -345,6 +344,8 @@ void ScopyMainWindow::handlePreferences(QString str, QVariant val)

} else if(str == "general_language") {
Q_EMIT p->restartRequired();
} else if(str == "general_show_status_bar") {
StatusManager::GetInstance()->setEnabled(val.toBool());
}
}

Expand Down Expand Up @@ -444,7 +445,32 @@ void ScopyMainWindow::removeDeviceFromUi(QString id)

void ScopyMainWindow::receiveVersionDocument(QJsonDocument document)
{
qInfo(CAT_SCOPY) << "The upstream scopy version is" << document << "and the current one is" << SCOPY_VERSION;
QJsonValue scopyJson = document["scopy"];
if(scopyJson.isNull()) {
qWarning(CAT_SCOPY) << "Could not find the entry \"scopy\" in the json document";
return;
}

QJsonValue scopyVersion = scopyJson["version"];
if(scopyVersion.isNull()) {
qWarning(CAT_SCOPY)
<< R"(Could not find the entry "version" in the "scopy" entry of the json document)";
return;
}

QVersionNumber currentScopyVersion = QVersionNumber::fromString(SCOPY_VERSION).normalized();
QVersionNumber upstreamScopyVersion =
QVersionNumber::fromString(scopyVersion.toString().remove(0, 1)).normalized();

if(upstreamScopyVersion > currentScopyVersion) {
StatusManager::GetInstance()->addTemporaryMessage(
"Your Scopy version of outdated. Please consider updating it. The newest version is " +
upstreamScopyVersion.toString(),
10000); // 10 sec
}

qInfo(CAT_SCOPY) << "The upstream scopy version is" << upstreamScopyVersion << "and the current one is"
<< currentScopyVersion;
}

#include "moc_scopymainwindow.cpp"
2 changes: 1 addition & 1 deletion core/src/scopymainwindow_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void ScopyMainWindow_API::acceptLicense()
}

if(m_w->checkUpdate) {
Q_EMIT m_w->checkUpdate->getExitBtn()->clicked();
Q_EMIT m_w->checkUpdate->setCheckVersion(false);
}
}

Expand Down
33 changes: 33 additions & 0 deletions core/src/versioncheckmessage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "versioncheckmessage.h"

#include <pluginbase/preferences.h>
#include <QHBoxLayout>

using namespace scopy;
VersionCheckMessage::VersionCheckMessage(QWidget *parent)
: QWidget(parent)
{
setLayout(new QHBoxLayout(this));
layout()->setContentsMargins(0, 0, 0, 0);
auto textLabel = new QLabel("Should Scopy check for online versions? [Yes](yes) [No](no)", this);
connect(textLabel, &QLabel::linkActivated, this, [this](const QString &text) {
if(text == "yes") {
setCheckVersion(true);
} else if(text == "no") {
setCheckVersion(false);
}

delete this;
});
textLabel->setTextFormat(Qt::MarkdownText);
textLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
layout()->addWidget(textLabel);

connect(this, &VersionCheckMessage::setCheckVersion, this, &VersionCheckMessage::saveCheckVersion);
}

VersionCheckMessage::~VersionCheckMessage() {}

void VersionCheckMessage::saveCheckVersion(bool allowed) { Preferences::set("general_check_online_version", allowed); }

#include "moc_versioncheckmessage.cpp"
36 changes: 0 additions & 36 deletions core/src/versioncheckoverlay.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion gui/include/gui/stylehelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SCOPY_GUI_EXPORT StyleHelper : public QObject
static void FrameBackgroundShadow(QFrame *w, QString objectName = "");
static void HoverWidget(QWidget *w, bool draggable = false, QString objectName = "");
static void TransparentWidget(QWidget *w, QString objectName = "");
static void ScopyStatusBar(QStatusBar *w, QString objectName = "");
static void ScopyStatusBar(QWidget *w, QString objectName = "");
static void ScopyHistoryList(QListWidget *w, QString objectName = "");

private:
Expand Down
49 changes: 20 additions & 29 deletions gui/include/gui/widgets/scopystatusbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,40 @@
#include <QStatusBar>
#include <QPushButton>
#include <QListWidget>
#include <QLabel>
#include <QList>
#include "hoverwidget.h"
#include "pluginbase/statusmessage.h"
#include "utils.h"
#include "menu_anim.hpp"
#include "scopy-gui_export.h"

namespace scopy {
class SCOPY_GUI_EXPORT ScopyStatusBar : public QStatusBar
class SCOPY_GUI_EXPORT ScopyStatusBar : public MenuVAnim
{
Q_OBJECT
QWIDGET_PAINT_EVENT_HELPER
public:
explicit ScopyStatusBar(QWidget *parent = nullptr);

Q_SIGNALS:
void requestHistory();

public Q_SLOTS:
/**
* @brief Verifies weather ScopyStatusBar can display a new status. It can display it if the current status
* is empty.
* */
void shouldDisplayNewStatus();

/**
* @brief Displays the received status.
* @param status A QString or a QWidget* that will be processed and displayed.
* @param ms The time the status will appear on screen, in milliseconds.
* */
void processStatus(QVariant status, int ms);

/**
* @brief Pops up the history of the last statuses.
* */
void showHistory(bool checked);

/**
* @brief overrides the current message with the one send as parameter.
* @param message QString with the urgent message
* @param ms The time that the message will be displayed (in milliseconds)
* */
void receiveUrgentMessage(QString message, int ms);
void displayStatus(StatusMessage *statusMessage);
void clearStatus();

private:
void initUi();
void initHistory();

QPushButton *m_historyButton;
QListWidget *m_historyList;
HoverWidget *m_hoverWidget;
void addToRight(QWidget *widget);
void addToLeft(QWidget *widget);

StatusMessage *m_message;

// UI elements
QWidget *m_leftWidget;
QWidget *m_rightWidget;
};
} // namespace scopy

Expand Down
4 changes: 2 additions & 2 deletions gui/src/stylehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,13 +1034,13 @@ void StyleHelper::TransparentWidget(QWidget *w, QString objectName)
w->setStyleSheet(style);
}

void StyleHelper::ScopyStatusBar(QStatusBar *w, QString objectName)
void StyleHelper::ScopyStatusBar(QWidget *w, QString objectName)
{
if(!objectName.isEmpty())
w->setObjectName(objectName);

QString style = QString(R"css(
QStatusBar {
QWidget {
background-color: &&UIElementBackground&&;
}
)css");
Expand Down
Loading

0 comments on commit eaf2ec2

Please sign in to comment.