| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2015-2020 Edouard Griffiths, F4EXB                              //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // API for features                                                              //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 as version 3 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 V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include <QEvent>
 | 
					
						
							|  |  |  | #include <QPainter>
 | 
					
						
							| 
									
										
										
										
											2020-06-07 02:24:26 +08:00
										 |  |  | #include <QPainterPath>
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include <QMouseEvent>
 | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <QDialog>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "gui/rollupwidget.h"
 | 
					
						
							|  |  |  | #include "ui_glspectrumgui.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RollupWidget::RollupWidget(QWidget* parent) : | 
					
						
							| 
									
										
										
										
											2017-11-14 22:58:35 +01:00
										 |  |  | 	QWidget(parent), | 
					
						
							| 
									
										
										
										
											2019-05-09 20:53:18 +02:00
										 |  |  | 	m_highlighted(false), | 
					
						
							|  |  |  |     m_contextMenuType(ContextMenuNone), | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  |     m_streamIndicator("S"), | 
					
						
							|  |  |  | 	m_channelWidget(true) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	setMinimumSize(250, 150); | 
					
						
							|  |  |  | 	setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); | 
					
						
							|  |  |  | 	setBackgroundRole(QPalette::Window); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	setAutoFillBackground(false); | 
					
						
							|  |  |  | 	setAttribute(Qt::WA_OpaquePaintEvent, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-05 22:11:17 +02:00
										 |  |  | 	// Vorgaben aus der Palette
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	m_titleColor = palette().highlight().color(); | 
					
						
							| 
									
										
										
										
											2017-10-05 22:11:17 +02:00
										 |  |  | 	m_titleTextColor = palette().highlightedText().color(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray RollupWidget::saveState(int version) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QByteArray state; | 
					
						
							|  |  |  | 	QDataStream stream(&state, QIODevice::WriteOnly); | 
					
						
							|  |  |  | 	int count = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	for (int i = 0; i < children().count(); ++i)  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		QWidget* r = qobject_cast<QWidget*>(children()[i]); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		if (r) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			count++; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	stream << VersionMarker; | 
					
						
							|  |  |  | 	stream << version; | 
					
						
							|  |  |  | 	stream << count; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	for (int i = 0; i < children().count(); ++i)  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		QWidget* r = qobject_cast<QWidget*>(children()[i]); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		if (r)  | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			stream << r->objectName(); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			if (r->isHidden()) { | 
					
						
							|  |  |  | 				stream << (int) 0; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				stream << (int) 1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return state; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool RollupWidget::restoreState(const QByteArray& state, int version) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	if (state.isEmpty()) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	QByteArray sd = state; | 
					
						
							|  |  |  | 	QDataStream stream(&sd, QIODevice::ReadOnly); | 
					
						
							|  |  |  | 	int marker, v; | 
					
						
							|  |  |  | 	stream >> marker; | 
					
						
							|  |  |  | 	stream >> v; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if ((stream.status() != QDataStream::Ok) || (marker != VersionMarker) || (v != version)) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int count; | 
					
						
							|  |  |  | 	stream >> count; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	if (stream.status() != QDataStream::Ok) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < count; ++i)  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		QString name; | 
					
						
							|  |  |  | 		int visible; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		stream >> name; | 
					
						
							|  |  |  | 		stream >> visible; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 		if (stream.status() != QDataStream::Ok) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 		for (int j = 0; j < children().count(); ++j)  | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			QWidget* r = qobject_cast<QWidget*>(children()[j]); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			if (r)  | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				if (r->objectName() == name)  | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					if (visible) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 						r->show(); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 					} else { | 
					
						
							|  |  |  | 						r->hide(); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RollupWidget::setTitleColor(const QColor& c) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_titleColor = c; | 
					
						
							| 
									
										
										
										
											2017-10-05 22:11:17 +02:00
										 |  |  | 	float l = 0.2126*c.redF() + 0.7152*c.greenF() + 0.0722*c.blueF(); | 
					
						
							|  |  |  | 	m_titleTextColor = l < 0.5f ? Qt::white : Qt::black; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 22:58:35 +01:00
										 |  |  | void RollupWidget::setHighlighted(bool highlighted) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_highlighted != highlighted) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_highlighted = highlighted; | 
					
						
							|  |  |  |         update(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | int RollupWidget::arrangeRollups() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QFontMetrics fm(font()); | 
					
						
							|  |  |  | 	int pos = fm.height() + 4; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  | 	for (int i = 0; i < children().count(); ++i) | 
					
						
							| 
									
										
										
										
											2017-08-24 02:05:48 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		QWidget* r = qobject_cast<QWidget*>(children()[i]); | 
					
						
							| 
									
										
										
										
											2017-08-24 02:05:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-24 19:42:25 +02:00
										 |  |  | 		if ((r != nullptr) && isRollupChild(r)) | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  | 		{ | 
					
						
							|  |  |  |             pos += fm.height() + 2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-24 19:42:25 +02:00
										 |  |  |             if (!r->isHidden()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 r->move(2, pos + 3); | 
					
						
							|  |  |  |                 int h = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (r->hasHeightForWidth()) { | 
					
						
							|  |  |  |                     h = r->heightForWidth(width() - 4); | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     h = r->sizeHint().height(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-24 19:42:25 +02:00
										 |  |  |                 r->resize(width() - 4, h); | 
					
						
							|  |  |  |                 pos += r->height() + 5; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-24 02:05:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	setMinimumHeight(pos); | 
					
						
							|  |  |  | 	setMaximumHeight(pos); | 
					
						
							| 
									
										
										
										
											2017-08-24 02:05:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	return pos; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RollupWidget::paintEvent(QPaintEvent*) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QPainter p(this); | 
					
						
							|  |  |  | 	QColor frame = palette().highlight().color(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Eigenbau
 | 
					
						
							|  |  |  | 	QFontMetrics fm(font()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	p.setRenderHint(QPainter::Antialiasing, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Ecken
 | 
					
						
							|  |  |  | 	p.setPen(Qt::NoPen); | 
					
						
							|  |  |  | 	p.setBrush(palette().base()); | 
					
						
							|  |  |  | 	p.drawRect(0, 0, 5, 5); | 
					
						
							|  |  |  | 	p.drawRect(width() - 5, 0, 5, 5); | 
					
						
							|  |  |  | 	p.drawRect(0, height() - 5, 5, 5); | 
					
						
							|  |  |  | 	p.drawRect(width() - 5, height() - 5, 5, 5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Rahmen
 | 
					
						
							| 
									
										
										
										
											2017-11-14 22:58:35 +01:00
										 |  |  | 	p.setPen(m_highlighted ? Qt::white : frame); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	p.setBrush(palette().window()); | 
					
						
							|  |  |  | 	QRectF r(rect()); | 
					
						
							|  |  |  | 	r.adjust(0.5, 0.5, -0.5, -0.5); | 
					
						
							|  |  |  | 	p.drawRoundedRect(r, 3.0, 3.0, Qt::AbsoluteSize); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Titel-Hintergrund
 | 
					
						
							|  |  |  | 	p.setPen(Qt::NoPen); | 
					
						
							|  |  |  | 	p.setBrush(m_titleColor); | 
					
						
							|  |  |  | 	QPainterPath path; | 
					
						
							|  |  |  | 	path.moveTo(1.5, fm.height() + 2.5); | 
					
						
							|  |  |  | 	path.lineTo(width() - 1.5, fm.height() + 2.5); | 
					
						
							|  |  |  | 	path.lineTo(width() - 1.5, 3.5); | 
					
						
							|  |  |  | 	path.arcTo(QRectF(width() - 3.5, 0, 2.5, 2.5), 270, -90); | 
					
						
							|  |  |  | 	path.lineTo(3.5, 1.5); | 
					
						
							|  |  |  | 	path.arcTo(QRectF(1.5, 2.5, 2.5, 2.5), 90, 90); | 
					
						
							|  |  |  | 	p.drawPath(path); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Titel-Abschlusslinie
 | 
					
						
							|  |  |  | 	p.setPen(frame); | 
					
						
							|  |  |  | 	p.drawLine(QPointF(0.5, 2 + fm.height() + 1.5), QPointF(width() - 1.5, 2 + fm.height() + 1.5)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Aktiv-Button links
 | 
					
						
							|  |  |  | 	p.setPen(QPen(palette().windowText().color(), 1.0)); | 
					
						
							|  |  |  | 	p.setBrush(palette().light()); | 
					
						
							|  |  |  | 	p.drawRoundedRect(QRectF(3.5, 3.5, fm.ascent(), fm.ascent()), 2.0, 2.0, Qt::AbsoluteSize); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	p.setPen(QPen(Qt::white, 1.0)); | 
					
						
							|  |  |  | 	p.drawText(QRectF(3.5, 2.5, fm.ascent(), fm.ascent()),  Qt::AlignCenter, "c"); | 
					
						
							| 
									
										
										
										
											2019-05-09 20:53:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	if (m_channelWidget) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// Stromkanal-Button links
 | 
					
						
							|  |  |  | 		p.setPen(QPen(palette().windowText().color(), 1.0)); | 
					
						
							|  |  |  | 		p.setBrush(palette().light()); | 
					
						
							|  |  |  | 		p.drawRoundedRect(QRectF(5.5 + fm.ascent(), 2.5, fm.ascent() + 2.0, fm.ascent() + 2.0), 2.0, 2.0, Qt::AbsoluteSize); | 
					
						
							|  |  |  | 		p.setPen(QPen(Qt::white, 1.0)); | 
					
						
							|  |  |  | 		p.drawText(QRectF(5.5 + fm.ascent(), 2.5, fm.ascent() + 2.0, fm.ascent() + 2.0),  Qt::AlignCenter, m_streamIndicator); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Schließen-Button rechts
 | 
					
						
							|  |  |  | 	p.setRenderHint(QPainter::Antialiasing, true); | 
					
						
							|  |  |  | 	p.setPen(QPen(palette().windowText().color(), 1.0)); | 
					
						
							|  |  |  | 	p.setBrush(palette().light()); | 
					
						
							|  |  |  | 	r = QRectF(width() - 3.5 - fm.ascent(), 3.5, fm.ascent(), fm.ascent()); | 
					
						
							|  |  |  | 	p.drawRoundedRect(r, 2.0, 2.0, Qt::AbsoluteSize); | 
					
						
							|  |  |  | 	p.setPen(QPen(palette().windowText().color(), 1.5)); | 
					
						
							|  |  |  | 	p.drawLine(r.topLeft() + QPointF(1, 1), r.bottomRight() + QPointF(-1, -1)); | 
					
						
							|  |  |  | 	p.drawLine(r.bottomLeft() + QPointF(1, -1), r.topRight() + QPointF(-1, 1)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Titel
 | 
					
						
							| 
									
										
										
										
											2017-10-05 22:11:17 +02:00
										 |  |  | 	//p.setPen(palette().highlightedText().color());
 | 
					
						
							|  |  |  | 	p.setPen(m_titleTextColor); | 
					
						
							| 
									
										
										
										
											2019-05-09 20:53:18 +02:00
										 |  |  | 	p.drawText(QRect(2 + 2*fm.height() + 2, 2, width() - 6 - 3*fm.height(), fm.height()), | 
					
						
							|  |  |  | 		fm.elidedText(windowTitle(), Qt::ElideMiddle, width() - 6 - 3*fm.height(), 0)); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Rollups
 | 
					
						
							|  |  |  | 	int pos = fm.height() + 4; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const QObjectList& c = children(); | 
					
						
							|  |  |  | 	QObjectList::ConstIterator w = c.begin(); | 
					
						
							|  |  |  | 	QObjectList::ConstIterator n = c.begin(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  | 	for (n = c.begin(); n != c.end(); ++n) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | 		if (qobject_cast<QWidget*>(*n) != nullptr) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (w = n; w != c.end(); w = n) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | 		if (n != c.end()) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			++n; | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (; n != c.end(); ++n) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  | 			if (qobject_cast<QWidget*>(*n) != nullptr) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         pos += paintRollup(qobject_cast<QWidget*>(*w), pos, &p, n == c.end(), frame); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int RollupWidget::paintRollup(QWidget* rollup, int pos, QPainter* p, bool last, const QColor& frame) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QFontMetrics fm(font()); | 
					
						
							|  |  |  | 	int height = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Titel-Abschlusslinie
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	if (!rollup->isHidden())  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		p->setPen(palette().dark().color()); | 
					
						
							|  |  |  | 		p->drawLine(QPointF(1.5, pos + fm.height() + 1.5), QPointF(width() - 1.5, pos + fm.height() + 1.5)); | 
					
						
							|  |  |  | 		p->setPen(palette().light().color()); | 
					
						
							|  |  |  | 		p->drawLine(QPointF(1.5, pos + fm.height() + 2.5), QPointF(width() - 1.5, pos + fm.height() + 2.5)); | 
					
						
							|  |  |  | 		height += 2; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	}  | 
					
						
							|  |  |  | 	else  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (!last)  | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			p->setPen(frame); | 
					
						
							|  |  |  | 			p->drawLine(QPointF(1.5, pos + fm.height() + 1.5), QPointF(width() - 1.5, pos + fm.height() + 1.5)); | 
					
						
							|  |  |  | 			height++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Titel
 | 
					
						
							|  |  |  | 	p->setPen(palette().windowText().color()); | 
					
						
							|  |  |  | 	p->drawText(QRect(2 + fm.height(), pos, width() - 4 - fm.height(), fm.height()), | 
					
						
							|  |  |  | 		fm.elidedText(rollup->windowTitle(), Qt::ElideMiddle, width() - 4 - fm.height(), 0)); | 
					
						
							|  |  |  | 	height += fm.height(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Ausklapp-Icon
 | 
					
						
							|  |  |  | 	p->setPen(palette().windowText().color()); | 
					
						
							|  |  |  | 	p->setBrush(palette().windowText()); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!rollup->isHidden())  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		QPolygonF a; | 
					
						
							|  |  |  | 		a.append(QPointF(3.5, pos + 2)); | 
					
						
							|  |  |  | 		a.append(QPointF(3.5 + fm.ascent(), pos + 2)); | 
					
						
							|  |  |  | 		a.append(QPointF(3.5 + fm.ascent() / 2.0, pos + fm.height() - 2)); | 
					
						
							|  |  |  | 		p->drawPolygon(a); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	}  | 
					
						
							|  |  |  | 	else  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		QPolygonF a; | 
					
						
							|  |  |  | 		a.append(QPointF(3.5, pos + 2)); | 
					
						
							|  |  |  | 		a.append(QPointF(3.5, pos + fm.height() - 2)); | 
					
						
							|  |  |  | 		a.append(QPointF(3.5 + fm.ascent(), pos + fm.height() / 2)); | 
					
						
							|  |  |  | 		p->drawPolygon(a); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Inhalt
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	if (!rollup->isHidden() && (!last))  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		// Rollup-Abschlusslinie
 | 
					
						
							|  |  |  | 		p->setPen(frame); | 
					
						
							|  |  |  | 		p->drawLine(QPointF(1.5, pos + fm.height() + rollup->height() + 6.5), | 
					
						
							|  |  |  | 					QPointF(width() - 1.5, pos + fm.height() + rollup->height() + 6.5)); | 
					
						
							|  |  |  | 		height += rollup->height() + 4; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return height; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RollupWidget::resizeEvent(QResizeEvent* size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	arrangeRollups(); | 
					
						
							|  |  |  | 	QWidget::resizeEvent(size); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RollupWidget::mousePressEvent(QMouseEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QFontMetrics fm(font()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// menu box left
 | 
					
						
							| 
									
										
										
										
											2019-05-09 20:53:18 +02:00
										 |  |  | 	if (QRectF(3.5, 3.5, fm.ascent(), fm.ascent()).contains(event->pos())) | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		m_contextMenuType = ContextMenuChannelSettings; | 
					
						
							| 
									
										
										
										
											2019-05-09 20:53:18 +02:00
										 |  |  | 		emit customContextMenuRequested(event->globalPos()); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	if (m_channelWidget) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// Stream channel menu left
 | 
					
						
							|  |  |  | 		if (QRectF(5.5 + fm.ascent(), 2.5, fm.ascent() + 2.0, fm.ascent() + 2.0).contains(event->pos())) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			m_contextMenuType = ContextMenuStreamSettings; | 
					
						
							|  |  |  | 			emit customContextMenuRequested(event->globalPos()); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// close button right
 | 
					
						
							|  |  |  | 	if(QRectF(width() - 3.5 - fm.ascent(), 3.5, fm.ascent(), fm.ascent()).contains(event->pos())) { | 
					
						
							|  |  |  | 		close(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// check if we need to change a rollup widget
 | 
					
						
							|  |  |  | 	int pos = fm.height() + 4; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < children().count(); ++i)  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		QWidget* r = qobject_cast<QWidget*>(children()[i]); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		if (r)  | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if ((event->y() >= pos) && (event->y() < (pos + fm.height() + 3)))  | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				if (r->isHidden())  | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 					r->show(); | 
					
						
							|  |  |  | 					//emit widgetRolled(r, true);
 | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 				}  | 
					
						
							|  |  |  | 				else  | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 					r->hide(); | 
					
						
							|  |  |  | 					//emit widgetRolled(r, false);
 | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 				arrangeRollups(); | 
					
						
							|  |  |  | 				repaint(); | 
					
						
							|  |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 			}  | 
					
						
							|  |  |  | 			else  | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 				pos += fm.height() + 2; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if (!r->isHidden()) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 					pos += r->height() + 5; | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool RollupWidget::event(QEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	if (event->type() == QEvent::ChildAdded)  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		((QChildEvent*)event)->child()->installEventFilter(this); | 
					
						
							|  |  |  | 		arrangeRollups(); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	}  | 
					
						
							|  |  |  | 	else if (event->type() == QEvent::ChildRemoved)  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		((QChildEvent*)event)->child()->removeEventFilter(this); | 
					
						
							|  |  |  | 		arrangeRollups(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	return QWidget::event(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool RollupWidget::eventFilter(QObject* object, QEvent* event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	if (event->type() == QEvent::Show)  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (children().contains(object))  | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			arrangeRollups(); | 
					
						
							|  |  |  | 			emit widgetRolled(qobject_cast<QWidget*>(object), true); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	}  | 
					
						
							|  |  |  | 	else if (event->type() == QEvent::Hide)  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (children().contains(object))  | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			arrangeRollups(); | 
					
						
							|  |  |  | 			emit widgetRolled(qobject_cast<QWidget*>(object), false); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	}  | 
					
						
							|  |  |  | 	else if (event->type() == QEvent::WindowTitleChange)  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (children().contains(object)) { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			repaint(); | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-20 01:06:34 +02:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	return QWidget::eventFilter(object, event); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-05-20 16:31:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void RollupWidget::setStreamIndicator(const QString& indicator) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_streamIndicator = indicator; | 
					
						
							|  |  |  | 	update(); | 
					
						
							| 
									
										
										
										
											2020-06-07 02:24:26 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-04 23:25:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | bool RollupWidget::isRollupChild(QWidget *childWidget) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return (qobject_cast<QDialog*>(childWidget) == nullptr); // exclude Dialogs from rollups
 | 
					
						
							|  |  |  | } |