Commit 0d164bca authored by Carsten Fuhrmann's avatar Carsten Fuhrmann
Browse files

fixed crash bug

parent d8cb025b
#include "ChannelListWidget.h"
#include <QMouseEvent>
ChannelListWidget::ChannelListWidget()
: QTreeWidget()
ChannelTree::ChannelTree(QWidget *parent)
: QTreeWidget(parent)
{
m_parent = new QWidget;
m_parent->setAttribute(Qt::WA_TranslucentBackground);
m_parent->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
m_parent->setGeometry(320, 200, 1, 1);
m_parent = parent;
setHeaderHidden(true);
setExpandsOnDoubleClick(false);
setStyleSheet("padding:2px;border-radius:5px;border-style:solid;border-width:1px;border-color:rgb(100,100,100); background-color:rgba(50,50,50,150); color:rgb(255,255,255);");
setParent(m_parent);
resize(200, 400);
m_parent->adjustSize();
m_parent->show();
}
ChannelListWidget::~ChannelListWidget()
ChannelTree::~ChannelTree()
{
setParent(NULL);
m_parent->deleteLater();
}
void ChannelListWidget::mousePressEvent(QMouseEvent * event)
void ChannelTree::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
isMouseDown = true;
......@@ -34,14 +29,14 @@ void ChannelListWidget::mousePressEvent(QMouseEvent * event)
QTreeWidget::mousePressEvent(event);
}
void ChannelListWidget::mouseReleaseEvent(QMouseEvent * event)
void ChannelTree::mouseReleaseEvent(QMouseEvent * event)
{
isMouseDown = false;
QTreeWidget::mouseReleaseEvent(event);
}
void ChannelListWidget::mouseMoveEvent(QMouseEvent * event)
void ChannelTree::mouseMoveEvent(QMouseEvent * event)
{
if (isMouseDown)
m_parent->move(event->globalPos());
......@@ -49,9 +44,33 @@ void ChannelListWidget::mouseMoveEvent(QMouseEvent * event)
QTreeWidget::mouseMoveEvent(event);
}
void ChannelListWidget::resizeEvent(QResizeEvent * event)
void ChannelTree::resizeEvent(QResizeEvent * event)
{
m_parent->adjustSize();
m_parent->resize(this->size());
QTreeWidget::resizeEvent(event);
}
\ No newline at end of file
}
///////////////////////////////////////////////////////////////////////////////////////
ChannelListWidget::ChannelListWidget(QWidget *parent)
: QWidget(parent)
{
setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
setGeometry(320, 200, 1, 1);
m_child = new ChannelTree(this);
m_child->show();
show();
}
ChannelListWidget::~ChannelListWidget()
{
m_child->deleteLater();
}
QTreeWidget * ChannelListWidget::getTree()
{
return (QTreeWidget*)m_child;
}
......@@ -3,13 +3,13 @@
#include <QPoint>
#include <QTreeWidget>
class ChannelListWidget : public QTreeWidget
class ChannelTree : public QTreeWidget
{
Q_OBJECT
public:
explicit ChannelListWidget();
~ChannelListWidget();
explicit ChannelTree(QWidget *parent);
~ChannelTree();
protected:
virtual void mousePressEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
......@@ -24,3 +24,20 @@ private:
public:
};
class ChannelListWidget : public QWidget
{
Q_OBJECT
public:
explicit ChannelListWidget(QWidget *parent = NULL);
~ChannelListWidget();
private:
ChannelTree *m_child;
public:
QTreeWidget* getTree();
};
......@@ -212,10 +212,10 @@ void OverlayController::updateChannelList()
void OverlayController::displayChannelList()
{
while (int nb = m_tree->topLevelItemCount())
while (int nb = m_tree->getTree()->topLevelItemCount())
{
auto item = m_tree->takeTopLevelItem(nb - 1);
disconnect(m_tree, &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked);
auto item = m_tree->getTree()->takeTopLevelItem(nb - 1);
disconnect(m_tree->getTree(), &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked);
delete item;
}
......@@ -254,7 +254,7 @@ void OverlayController::displayChannelList()
for (auto& it : channelList)
{
if (it.parent == 0)
m_tree->addTopLevelItem(it.entry);
m_tree->getTree()->addTopLevelItem(it.entry);
else
{
bool found(false);
......@@ -294,8 +294,8 @@ void OverlayController::displayChannelList()
}
}
m_tree->expandAll();
connect(m_tree, &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked);
m_tree->getTree()->expandAll();
connect(m_tree->getTree(), &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked);
m_tree->adjustSize();
m_tree->show();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment