MSWSP: add parse_CNatLanguageRestriction()
[wireshark-wip.git] / ui / qt / label_stack.cpp
blobadc87da1186ee4a03d3d9a038b9f1968b6e02a47
1 /* label_stack.cpp
3 * $Id$
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "label_stack.h"
25 #include <QMouseEvent>
26 #include <QContextMenuEvent>
28 #include "tango_colors.h"
30 /* Temporary message timeouts */
31 const int temporary_interval_ = 1000;
32 const int temporary_msg_timeout_ = temporary_interval_ * 9;
33 const int temporary_flash_timeout_ = temporary_interval_ / 5;
34 const int num_flashes_ = 3;
36 LabelStack::LabelStack(QWidget *parent) :
37 QLabel(parent)
39 #ifdef Q_OS_MAC
40 setAttribute(Qt::WA_MacSmallSize, true);
41 #endif
42 temporary_ctx_ = -1;
43 fillLabel();
45 connect(&temporary_timer_, SIGNAL(timeout()), this, SLOT(updateTemporaryStatus()));
48 void LabelStack::setTemporaryContext(const int ctx) {
49 temporary_ctx_ = ctx;
52 void LabelStack::fillLabel() {
53 StackItem *si;
54 QString style_sheet;
56 style_sheet =
57 "QLabel {"
58 " margin-left: 0.5em;";
60 if (labels_.isEmpty()) {
61 clear();
62 return;
65 si = labels_.first();
67 if (si->ctx == temporary_ctx_) {
68 style_sheet += QString(
69 " border-radius: 0.25em;"
70 " color: #%1;"
71 " background-color: #%2;"
73 .arg(ws_css_warn_text, 6, 16, QChar('0'))
74 .arg(ws_css_warn_background, 6, 16, QChar('0'));
77 style_sheet += "}";
78 setStyleSheet(style_sheet);
79 setText(si->text);
82 void LabelStack::pushText(QString &text, int ctx) {
83 StackItem *si = new StackItem;
85 if (ctx == temporary_ctx_) {
86 temporary_timer_.stop();
87 popText(temporary_ctx_);
89 temporary_epoch_.start();
90 temporary_timer_.start(temporary_flash_timeout_);
91 emit toggleTemporaryFlash(true);
94 si->text = text;
95 si->ctx = ctx;
96 labels_.prepend(si);
97 fillLabel();
100 void LabelStack::mousePressEvent(QMouseEvent *event)
102 if (event->button() == Qt::LeftButton)
103 emit mousePressedAt(QPoint(event->globalPos()), Qt::LeftButton);
106 void LabelStack::mouseReleaseEvent(QMouseEvent *event)
108 Q_UNUSED(event);
111 void LabelStack::mouseDoubleClickEvent(QMouseEvent *event)
113 Q_UNUSED(event);
116 void LabelStack::mouseMoveEvent(QMouseEvent *event)
118 Q_UNUSED(event);
121 void LabelStack::contextMenuEvent(QContextMenuEvent *event)
123 emit mousePressedAt(QPoint(event->globalPos()), Qt::RightButton);
126 void LabelStack::popText(int ctx) {
127 QMutableListIterator<StackItem *> iter(labels_);
129 while (iter.hasNext()) {
130 if (iter.next()->ctx == ctx) {
131 iter.remove();
132 break;
136 fillLabel();
139 void LabelStack::updateTemporaryStatus() {
140 if (temporary_epoch_.elapsed() >= temporary_msg_timeout_) {
141 popText(temporary_ctx_);
142 emit toggleTemporaryFlash(false);
143 temporary_timer_.stop();
144 } else {
145 for (int i = (num_flashes_ * 2); i > 0; i--) {
146 if (temporary_epoch_.elapsed() >= temporary_flash_timeout_ * i) {
147 emit toggleTemporaryFlash(i % 2);
148 break;
155 * Editor modelines
157 * Local Variables:
158 * c-basic-offset: 4
159 * tab-width: 8
160 * indent-tabs-mode: nil
161 * End:
163 * ex: set shiftwidth=4 tabstop=8 expandtab:
164 * :indentSize=4:tabSize=8:noTabs=true: