Commit 0889b855 authored by Carsten Fuhrmann's avatar Carsten Fuhrmann
Browse files

added custom widget to make the semitransparent channel list movable

Bug:
crash when there is a connection and i deactivate the plugin
parent 5b6484ac
#include "ChannelListWidget.h"
#include <QMouseEvent>
ChannelListWidget::ChannelListWidget()
: QTreeWidget()
{
m_parent = new QWidget;
m_parent->setAttribute(Qt::WA_TranslucentBackground);
m_parent->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
m_parent->setGeometry(320, 200, 1, 1);
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()
{
//m_parent->deleteLater();
}
void ChannelListWidget::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
isMouseDown = true;
QTreeWidget::mousePressEvent(event);
}
void ChannelListWidget::mouseReleaseEvent(QMouseEvent * event)
{
isMouseDown = false;
QTreeWidget::mouseReleaseEvent(event);
}
void ChannelListWidget::mouseMoveEvent(QMouseEvent * event)
{
if (isMouseDown)
m_parent->move(event->globalPos());
QTreeWidget::mouseMoveEvent(event);
}
void ChannelListWidget::resizeEvent(QResizeEvent * event)
{
m_parent->adjustSize();
QTreeWidget::resizeEvent(event);
}
\ No newline at end of file
#pragma once
#include <QWidget>
#include <QPoint>
#include <QTreeWidget>
class ChannelListWidget : public QTreeWidget
{
Q_OBJECT
public:
explicit ChannelListWidget();
~ChannelListWidget();
protected:
virtual void mousePressEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
virtual void mouseMoveEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
virtual void resizeEvent(QResizeEvent * event) Q_DECL_OVERRIDE;
private:
bool isMouseDown = false;
QWidget *m_parent;
public:
};
......@@ -6,6 +6,7 @@
#include <qdebug.h>
#include "teamspeak\public_errors.h"
//#ifndef _DEBUG
//#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
//#endif
......@@ -41,13 +42,7 @@ OverlayController::OverlayController(const struct TS3Functions funcs, quint64 se
m_SCHID = serverConnectionHandlerID;
m_treeWidget = new QWidget;
m_tree = new QTreeWidget(m_treeWidget);
m_tree->setHeaderHidden(true);
m_tree->setExpandsOnDoubleClick(false);
m_treeWidget->setAttribute(Qt::WA_TranslucentBackground);
m_treeWidget->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Tool);
m_tree = new ChannelListWidget;
}
OverlayController::~OverlayController()
......@@ -61,7 +56,7 @@ OverlayController::~OverlayController()
m_msgLines.clear();
delete m_debugWindow;
delete m_treeWidget;
delete m_tree;
}
void OverlayController::deleteChatLine(QWidget * line)
......@@ -210,7 +205,7 @@ void OverlayController::reset()
void OverlayController::updateChannelList()
{
if (m_treeWidget->isVisible())
if (m_tree->isVisible())
displayChannelList();
}
......@@ -298,6 +293,5 @@ void OverlayController::displayChannelList()
m_tree->expandAll();
connect(m_tree, &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked);
m_tree->adjustSize();
m_treeWidget->adjustSize();
m_treeWidget->show();
m_tree->show();
}
......@@ -7,7 +7,7 @@
#include <QWidget>
#include <QVector>
#include <QLabel>
#include <QTreeWidget>
#include "ChannelListWidget.h"
#define MAXLINES 5
......@@ -34,8 +34,7 @@ private:
QLabel* m_debugWindow;
QVector<QWidget*> m_speakers;
QVector<QWidget*> m_msgLines;
QTreeWidget* m_tree;
QWidget* m_treeWidget;
ChannelListWidget* m_tree;
private:
void deleteChatLine(QWidget* line);
......
......@@ -102,8 +102,22 @@ QString channelID2Name(uint64 serverConnectionHandlerID, uint64 channelID)
return name;
}
OverlayController* getController(uint64 serverConnectionHandlerID)
OverlayController* getController(uint64 serverConnectionHandlerID = 0)
{
if (serverConnectionHandlerID == 0)
{
OverlayController* ret = NULL;
for (auto &it : g_serverList.keys())
{
int tmp;
if (ts3Functions.getClientSelfVariableAsInt(it, CLIENT_IS_MUTED, &tmp) != ERROR_ok)
if (tmp == 0)
ret = g_serverList.find(it).value();
}
return ret;
}
auto tmp = g_serverList.find(serverConnectionHandlerID);
if (tmp == g_serverList.end())
......@@ -309,9 +323,7 @@ void ts3plugin_initHotkeys(struct PluginHotkey*** hotkeys) {
* The keyword will be later passed to ts3plugin_onHotkeyEvent to identify which hotkey was triggered.
* The description is shown in the clients hotkey dialog. */
BEGIN_CREATE_HOTKEYS(3); /* Create 3 hotkeys. Size must be correct for allocating memory. */
CREATE_HOTKEY("keyword_1", "Test hotkey 1");
CREATE_HOTKEY("keyword_2", "Test hotkey 2");
CREATE_HOTKEY("keyword_3", "Test hotkey 3");
CREATE_HOTKEY("Channellist", "Displays a simple channellist of the server");
END_CREATE_HOTKEYS;
/* The client will call ts3plugin_freeMemory to release all allocated memory */
......@@ -400,13 +412,6 @@ void ts3plugin_onClientMoveEvent(uint64 serverConnectionHandlerID, anyID clientI
{
getController(serverConnectionHandlerID)->addChatLine(QString("%1 <font size=\"-5\">connected to</font> %2").arg(ClientName).arg(newChannel));
}
else if (!ClientName.isEmpty() && !oldChannel.isEmpty() && newChannel.isEmpty())
{
if(oldChannelID == getCurrentChannel(serverConnectionHandlerID))
getController(serverConnectionHandlerID)->addChatLine(QString("<font color=\"#00FFFF\">%1 <font size=\"-5\">disconnected from</font> %2</font>").arg(ClientName).arg(oldChannel));
else
getController(serverConnectionHandlerID)->addChatLine(QString("%1 <font size=\"-5\">disconnected from</font> %2").arg(ClientName).arg(oldChannel));
}
}
......@@ -767,7 +772,9 @@ void ts3plugin_onMenuItemEvent(uint64 serverConnectionHandlerID, enum PluginMenu
/* This function is called if a plugin hotkey was pressed. Omit if hotkeys are unused. */
void ts3plugin_onHotkeyEvent(const char* keyword) {
printf("PLUGIN: Hotkey event: %s\n", keyword);
/* Identify the hotkey by keyword ("keyword_1", "keyword_2" or "keyword_3" in this example) and handle here... */
if (QString(keyword) == "Channellist")
getController()->debugPrint("WUHU");
}
/* Called when recording a hotkey has finished after calling ts3Functions.requestHotkeyInputDialog */
......
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