Aufgrund einer Wartung wird GitLab am 17.08. zwischen 8:30 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 17.08. between 8:30 and 9:00 am.

ChannelListWidget.cpp 4.25 KB
Newer Older
1 2
#include "ChannelListWidget.h"
#include <QMouseEvent>
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
3
#include <Windows.h>
4
#include <QBoxLayout>
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
5
#include <QFile>
6
#include <QApplication>
7

8

9
ChannelTree::ChannelTree(ChannelListWidget * widget, QWidget *parent)
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
10
	: QTreeWidget(parent)
11
{
12
	m_parent = widget;
13 14 15

	setHeaderHidden(true);
	setExpandsOnDoubleClick(false);
16

17
	m_delegate = new MyItemDelegate;
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
18
	//setItemDelegate(m_delegate);
19

Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
20 21 22 23 24 25
	QFile styleSheet("plugins\\qtTsOverlay\\tree.styl");
	styleSheet.open(QIODevice::ReadOnly);
	setStyleSheet(styleSheet.readAll());
	styleSheet.close();

	setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
26 27
	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
28 29 30

	setAttribute(Qt::WA_ShowWithoutActivating);
	setFocusPolicy(Qt::NoFocus);
31 32
}

Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
33
ChannelTree::~ChannelTree()
34
{
35
	delete m_delegate;
36 37
}

Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
38
void ChannelTree::mousePressEvent(QMouseEvent * event)
39 40
{
	if (event->button() == Qt::LeftButton)
41 42 43 44
	{
		m_oldPosition = event->globalPos();
		doMove = true;
	}
45 46
	else if (event->button() == Qt::RightButton)
		m_parent->hide();
47 48 49 50

	QTreeWidget::mousePressEvent(event);
}

Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
51
void ChannelTree::mouseReleaseEvent(QMouseEvent * event)
52
{
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
53
	doMove = false;
54 55 56 57

	QTreeWidget::mouseReleaseEvent(event);
}

Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
58
void ChannelTree::mouseMoveEvent(QMouseEvent * event)
59
{
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
60
	if (doMove)
61 62 63 64
	{
		m_parent->move(m_parent->pos() + (event->globalPos() - m_oldPosition));
		m_oldPosition = event->globalPos();
	}
65 66 67 68

	QTreeWidget::mouseMoveEvent(event);
}

Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
69

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
///////////////////////////////////////////////////////////////////////////////////////

Background::Background(ChannelListWidget * widget, QWidget *parent)
	: QLabel(parent)
{
	m_parent = widget;

	QFile styleSheet("plugins\\qtTsOverlay\\background.styl");
	styleSheet.open(QIODevice::ReadOnly);
	setStyleSheet(styleSheet.readAll());
	styleSheet.close();
}

Background::~Background()
{

}

void Background::mousePressEvent(QMouseEvent * event)
{
	if (event->button() == Qt::LeftButton)
91 92
	{
		m_oldPosition = event->globalPos();
93
		doMove = true;
94
	}
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	else if (event->button() == Qt::RightButton)
		m_parent->hide();

	QLabel::mousePressEvent(event);
}

void Background::mouseReleaseEvent(QMouseEvent * event)
{
	doMove = false;

	QLabel::mouseReleaseEvent(event);
}

void Background::mouseMoveEvent(QMouseEvent * event)
{
	if (doMove)
111 112 113 114
	{
		m_parent->move(m_parent->pos() + (event->globalPos() - m_oldPosition));
		m_oldPosition = event->globalPos();
	}
115 116 117 118 119

	QLabel::mouseMoveEvent(event);
}


Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
120 121 122 123 124
///////////////////////////////////////////////////////////////////////////////////////

ChannelListWidget::ChannelListWidget(QWidget *parent)
	: QWidget(parent)
{
125 126
	m_state = full;

127
	m_minIcon.addFile("plugins\\qtTsOverlay\\min.png");
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
128
	m_minIcon.addFile("plugins\\qtTsOverlay\\min.png", QSize(), QIcon::Selected);
129
	m_maxIcon.addFile("plugins\\qtTsOverlay\\max.png");
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
130
	m_maxIcon.addFile("plugins\\qtTsOverlay\\max.png", QSize(), QIcon::Selected);
131

Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
132
	setAttribute(Qt::WA_TranslucentBackground);
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
133 134
	setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::SplashScreen);
	move(320, 200);
135

136
	m_background = new Background(this, this);
137

138 139 140 141
	QVBoxLayout* layout = new QVBoxLayout(this);
	layout->setMargin(0);
	layout->setSpacing(0);

142
	m_button = new QPushButton(this);
143
	m_button->setIcon(m_minIcon);
144
	m_button->setIconSize(QSize(8,8));
145 146 147 148 149 150 151
	connect(m_button, &QPushButton::pressed, this, &ChannelListWidget::buttonPressed);
	QFile style("plugins\\qtTsOverlay\\button.styl");
	style.open(QIODevice::ReadOnly);
	m_button->setStyleSheet(style.readAll());
	style.close();
	layout->addWidget(m_button, 0, Qt::AlignTop | Qt::AlignRight);

Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
152
	m_child = new ChannelTree(this);
153 154 155 156 157
	layout->addWidget(m_child);

	m_grip = new QSizeGrip(this);
	layout->addWidget(m_grip, 0, Qt::AlignBottom | Qt::AlignRight);

Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
158 159 160 161 162
	show();
}

ChannelListWidget::~ChannelListWidget()
{
163 164
	delete m_child;
	delete m_grip;
165
	delete m_background;
166
	delete m_button;
Carsten Fuhrmann's avatar
Carsten Fuhrmann committed
167 168 169 170 171 172
}

QTreeWidget * ChannelListWidget::getTree()
{
	return (QTreeWidget*)m_child;
}
173

174 175 176 177 178
void ChannelListWidget::buttonPressed()
{
	if (m_state == full)
	{
		m_state = minimum;
179
		m_button->setIcon(m_maxIcon);
180 181 182 183
	}
	else
	{
		m_state = full;
184
		m_button->setIcon(m_minIcon);
185 186 187 188 189
	}

	emit treeStateChanged(m_state);
}

190 191 192 193
void ChannelListWidget::resizeEvent(QResizeEvent *event)
{
	QWidget::resizeEvent(event);

194 195
	m_child->resize(m_child->size() - (event->oldSize() - event->size()));
	m_background->resize(size());
196
}