HTML overlay status message, smaller form of overlay message

* improved toHTML (with icon)
* overlay message
This commit is contained in:
Klaus Basan
2018-11-16 00:52:23 +01:00
parent d9788115c7
commit 753511cafb
9 changed files with 137 additions and 28 deletions

View File

@@ -117,7 +117,7 @@ namespace BlackGui
void CLogComponent::appendStatusMessageToConsole(const CStatusMessage &statusMessage)
{
if (statusMessage.isEmpty()) return;
ui->tep_StatusPageConsole->appendHtml(statusMessage.toHtml());
ui->tep_StatusPageConsole->appendHtml(statusMessage.toHtml(false));
}
void CLogComponent::appendPlainTextToConsole(const QString &text)

View File

@@ -499,6 +499,7 @@ namespace BlackGui
QSizeF CGuiUtility::fontMetrics80Chars(bool withRatio)
{
// scale is 3.0 on my hires display
static const QString s("01234567890123456789012345678901234567890123456789012345678901234567890123456789");
const QFontMetricsF fm = CGuiUtility::currentFontMetricsF();
const qreal scale = withRatio ? CGuiUtility::mainApplicationWidgetPixelRatio() : 1.0;
@@ -522,11 +523,12 @@ namespace BlackGui
{
// 1920/1080: 560/16 256/16 => 530/960
// 3840/2160: 400/10 178/10 => 375/600
// with ratio we get the physical solution, otherwise logical solution
const QSizeF s1 = CGuiUtility::fontMetrics80Chars(withRatio);
const QSizeF s2 = CGuiUtility::fontMetricsLazyDog43Chars(withRatio);
const QSizeF s = s1 + s2;
const qreal w = s.width() * xCharacters / 123;
const qreal h = s.height() * yCharacters / 2;
const qreal w = s.width() * xCharacters / 123; // 123 chars
const qreal h = s.height() * yCharacters / 2; // 2 lines
return QSizeF(w, h);
}

View File

@@ -74,7 +74,7 @@ namespace BlackGui
{
// the underlying model object as summary
const CStatusMessage msg(this->at(index));
return msg.toHtml();
return msg.toHtml(false);
}
return CListModelTimestampObjects::data(index, role);
}

View File

@@ -54,7 +54,7 @@ namespace BlackGui
{
this->init(w, h);
this->showKillButton(false);
connect(sGui, &CGuiApplication::styleSheetsChanged, this, &COverlayMessages::onStyleSheetsChanged, Qt::QueuedConnection);
if (sGui) { connect(sGui, &CGuiApplication::styleSheetsChanged, this, &COverlayMessages::onStyleSheetsChanged, Qt::QueuedConnection); }
connect(ui->pb_Ok, &QPushButton::clicked, this, &COverlayMessages::onOkClicked);
connect(ui->pb_Cancel, &QPushButton::clicked, this, &COverlayMessages::onCancelClicked);
connect(ui->tb_Kill, &QPushButton::clicked, this, &COverlayMessages::onKillClicked);
@@ -126,7 +126,7 @@ namespace BlackGui
msgBox.setInformativeText("Do you want to terminate " + sGui->getApplicationNameAndVersion() + "?");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
if (QMessageBox::Ok == msgBox.exec())
if (QMessageBox::Ok == msgBox.exec() && sGui)
{
sGui->gracefulShutdown();
sGui->exit();
@@ -328,6 +328,28 @@ namespace BlackGui
}
}
void COverlayMessages::showHTMLMessage(const CStatusMessage &message, int timeOutMs)
{
if (message.isEmpty()) { return; }
if (!sGui || sGui->isShuttingDown()) { return; }
if (this->hasPendingConfirmation())
{
// defer message
QPointer<COverlayMessages> myself(this);
m_pendingMessageCalls.push_back([ = ]()
{
if (!myself) { return; }
myself->showHTMLMessage(message, timeOutMs);
});
return;
}
this->setModeToHTMLMessage();
ui->te_HTMLMessage->setText(message.toHtml(true));
this->display(timeOutMs);
}
void COverlayMessages::showKillButton(bool killButton)
{
m_hasKillButton = killButton;
@@ -355,6 +377,13 @@ namespace BlackGui
this->setHeader("Message");
}
void COverlayMessages::setModeToHTMLMessage(bool withKillButton)
{
ui->sw_StatusMessagesComponent->setCurrentWidget(ui->pg_HTMLMessage);
this->showKill(withKillButton);
this->setHeader("Message");
}
void COverlayMessages::setModeToTextMessage()
{
ui->sw_StatusMessagesComponent->setCurrentWidget(ui->pg_TextMessage);

View File

@@ -62,6 +62,9 @@ namespace BlackGui
//! Single Message mode
void setModeToMessageSmall(bool withKillButton = false);
//! HTML message mode
void setModeToHTMLMessage(bool withKillButton = false);
//! Single Text message mode
void setModeToTextMessage();
@@ -110,6 +113,9 @@ namespace BlackGui
//! Display one of the supported types
void showOverlayVariant(const BlackMisc::CVariant &variant, int timeOutMs = -1);
//! HTML message
void showHTMLMessage(const BlackMisc::CStatusMessage &message, int timeOutMs = -1);
//! Allows to globally enable/disable kill button
void showKillButton(bool killButton);

View File

@@ -113,7 +113,7 @@
<item>
<widget class="QStackedWidget" name="sw_StatusMessagesComponent">
<property name="currentIndex">
<number>5</number>
<number>6</number>
</property>
<widget class="QWidget" name="pg_StatusMessages">
<layout class="QVBoxLayout" name="vl_PgStatusMessages">
@@ -321,6 +321,25 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="pg_HTMLMessage">
<layout class="QVBoxLayout" name="vl_HTMLMessage">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTextEdit" name="te_HTMLMessage"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>

View File

@@ -163,6 +163,14 @@ namespace BlackGui
WIDGET::repaint();
}
//! \copydoc BlackGui::COverlayMessages::showHTMLMessage
void showOverlayHTMLMessage(const BlackMisc::CStatusMessage &message, int timeOutMs = -1)
{
this->initMinimalFrame();
m_overlayMessages->showHTMLMessage(message, timeOutMs);
WIDGET::repaint();
}
//! \copydoc BlackGui::COverlayMessages::showOverlayImage
void showOverlayInlineTextMessage(Components::TextMessageTab tab)
{
@@ -206,6 +214,25 @@ namespace BlackGui
m_overlayMessages->setGeometry(x, y, w, h);
}
//! Init a minimal frame (smaller as the normal one)
void initMinimalFrame()
{
this->initInnerFrame();
// get logical resolution
constexpr int MinHeight = 100;
QSizeF s = CGuiUtility::fontMetricsEstimateSize(100, 5); // 2 lines for header
if (s.height() < MinHeight) { s.setHeight(MinHeight); }
const QSize inner(innerFrameSize());
const QPoint middle = WIDGET::geometry().center();
const int w = qMin(inner.width(), qRound(s.width()));
const int h = qMin(inner.height(), qRound(s.height()));
const int x = middle.x() - w / 2;
const int y = qRound(middle.y() - h / m_middleFactor);
m_overlayMessages->setGeometry(x, y, w, h);
}
//! \copydoc QFrame::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event) override
{