2012-01-14 00:16:16 +00:00
|
|
|
/* label_stack.cpp
|
|
|
|
*
|
2012-10-31 15:40:55 +00:00
|
|
|
* $Id$
|
2012-01-14 00:16:16 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2012-01-14 00:16:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "label_stack.h"
|
2012-12-30 19:33:05 +00:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QContextMenuEvent>
|
2012-01-14 00:16:16 +00:00
|
|
|
|
2012-11-30 23:14:53 +00:00
|
|
|
#include "tango_colors.h"
|
2012-01-14 00:16:16 +00:00
|
|
|
|
|
|
|
/* Temporary message timeouts */
|
2012-11-30 23:14:53 +00:00
|
|
|
const int temporary_interval_ = 1000;
|
|
|
|
const int temporary_msg_timeout_ = temporary_interval_ * 9;
|
|
|
|
const int temporary_flash_timeout_ = temporary_interval_ / 5;
|
|
|
|
const int num_flashes_ = 3;
|
2012-01-14 00:16:16 +00:00
|
|
|
|
|
|
|
LabelStack::LabelStack(QWidget *parent) :
|
|
|
|
QLabel(parent)
|
|
|
|
{
|
2012-08-01 00:06:21 +00:00
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
setAttribute(Qt::WA_MacSmallSize, true);
|
|
|
|
#endif
|
2012-11-30 23:14:53 +00:00
|
|
|
temporary_ctx_ = -1;
|
2012-01-14 00:16:16 +00:00
|
|
|
fillLabel();
|
2012-11-30 23:14:53 +00:00
|
|
|
|
|
|
|
connect(&temporary_timer_, SIGNAL(timeout()), this, SLOT(updateTemporaryStatus()));
|
2012-01-14 00:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LabelStack::setTemporaryContext(int ctx) {
|
2012-11-30 23:14:53 +00:00
|
|
|
temporary_ctx_ = ctx;
|
2012-01-14 00:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LabelStack::fillLabel() {
|
|
|
|
StackItem *si;
|
2012-11-30 23:14:53 +00:00
|
|
|
QString style_sheet;
|
2012-01-14 00:16:16 +00:00
|
|
|
|
2012-11-30 23:14:53 +00:00
|
|
|
style_sheet =
|
2012-01-14 00:16:16 +00:00
|
|
|
"QLabel {"
|
2012-11-30 23:14:53 +00:00
|
|
|
" margin-left: 0.5em;";
|
2012-01-14 00:16:16 +00:00
|
|
|
|
2012-11-30 23:14:53 +00:00
|
|
|
if (labels_.isEmpty()) {
|
2012-01-14 00:16:16 +00:00
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-30 23:14:53 +00:00
|
|
|
si = labels_.first();
|
|
|
|
|
|
|
|
if (si->ctx == temporary_ctx_) {
|
|
|
|
style_sheet += QString(
|
2012-12-07 20:08:00 +00:00
|
|
|
" border-radius: 0.25em;"
|
|
|
|
" color: #%1;"
|
|
|
|
" background-color: #%2;"
|
|
|
|
)
|
2012-12-21 17:37:57 +00:00
|
|
|
.arg(ws_css_warn_text, 6, 16, QChar('0'))
|
|
|
|
.arg(ws_css_warn_background, 6, 16, QChar('0'));
|
2012-01-14 00:16:16 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 23:14:53 +00:00
|
|
|
style_sheet += "}";
|
|
|
|
setStyleSheet(style_sheet);
|
2012-01-14 00:16:16 +00:00
|
|
|
setText(si->text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LabelStack::pushText(QString &text, int ctx) {
|
|
|
|
StackItem *si = new StackItem;
|
|
|
|
|
2012-11-30 23:14:53 +00:00
|
|
|
if (ctx == temporary_ctx_) {
|
2012-12-15 01:04:39 +00:00
|
|
|
temporary_timer_.stop();
|
|
|
|
popText(temporary_ctx_);
|
|
|
|
|
2012-11-30 23:14:53 +00:00
|
|
|
temporary_epoch_.start();
|
|
|
|
temporary_timer_.start(temporary_flash_timeout_);
|
|
|
|
emit toggleTemporaryFlash(true);
|
2012-01-14 00:16:16 +00:00
|
|
|
}
|
|
|
|
|
2012-12-15 01:04:39 +00:00
|
|
|
si->text = text;
|
|
|
|
si->ctx = ctx;
|
|
|
|
labels_.prepend(si);
|
2012-01-14 00:16:16 +00:00
|
|
|
fillLabel();
|
|
|
|
}
|
|
|
|
|
2012-12-30 19:33:05 +00:00
|
|
|
void LabelStack::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
emit mousePressedAt(QPoint(event->globalPos()), Qt::LeftButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LabelStack::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LabelStack::mouseDoubleClickEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LabelStack::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LabelStack::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
{
|
|
|
|
emit mousePressedAt(QPoint(event->globalPos()), Qt::RightButton);
|
|
|
|
}
|
|
|
|
|
2012-01-14 00:16:16 +00:00
|
|
|
void LabelStack::popText(int ctx) {
|
2012-11-30 23:14:53 +00:00
|
|
|
QMutableListIterator<StackItem *> iter(labels_);
|
2012-01-14 00:16:16 +00:00
|
|
|
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
if (iter.next()->ctx == ctx) {
|
|
|
|
iter.remove();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fillLabel();
|
|
|
|
}
|
|
|
|
|
2012-11-30 23:14:53 +00:00
|
|
|
void LabelStack::updateTemporaryStatus() {
|
|
|
|
if (temporary_epoch_.elapsed() >= temporary_msg_timeout_) {
|
|
|
|
popText(temporary_ctx_);
|
|
|
|
emit toggleTemporaryFlash(false);
|
|
|
|
temporary_timer_.stop();
|
|
|
|
} else {
|
|
|
|
for (int i = (num_flashes_ * 2); i > 0; i--) {
|
|
|
|
if (temporary_epoch_.elapsed() >= temporary_flash_timeout_ * i) {
|
|
|
|
emit toggleTemporaryFlash(i % 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-14 00:16:16 +00:00
|
|
|
}
|
2012-09-04 08:18:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|