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
) :
40 setAttribute(Qt::WA_MacSmallSize
, true);
45 connect(&temporary_timer_
, SIGNAL(timeout()), this, SLOT(updateTemporaryStatus()));
48 void LabelStack::setTemporaryContext(const int ctx
) {
52 void LabelStack::fillLabel() {
58 " margin-left: 0.5em;";
60 if (labels_
.isEmpty()) {
67 if (si
->ctx
== temporary_ctx_
) {
68 style_sheet
+= QString(
69 " border-radius: 0.25em;"
71 " background-color: #%2;"
73 .arg(ws_css_warn_text
, 6, 16, QChar('0'))
74 .arg(ws_css_warn_background
, 6, 16, QChar('0'));
78 setStyleSheet(style_sheet
);
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);
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
)
111 void LabelStack::mouseDoubleClickEvent(QMouseEvent
*event
)
116 void LabelStack::mouseMoveEvent(QMouseEvent
*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
) {
139 void LabelStack::updateTemporaryStatus() {
140 if (temporary_epoch_
.elapsed() >= temporary_msg_timeout_
) {
141 popText(temporary_ctx_
);
142 emit
toggleTemporaryFlash(false);
143 temporary_timer_
.stop();
145 for (int i
= (num_flashes_
* 2); i
> 0; i
--) {
146 if (temporary_epoch_
.elapsed() >= temporary_flash_timeout_
* i
) {
147 emit
toggleTemporaryFlash(i
% 2);
160 * indent-tabs-mode: nil
163 * ex: set shiftwidth=4 tabstop=8 expandtab:
164 * :indentSize=4:tabSize=8:noTabs=true: