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

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 @@ ...@@ -6,6 +6,7 @@
#include <qdebug.h> #include <qdebug.h>
#include "teamspeak\public_errors.h" #include "teamspeak\public_errors.h"
//#ifndef _DEBUG //#ifndef _DEBUG
//#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) //#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
//#endif //#endif
...@@ -41,13 +42,7 @@ OverlayController::OverlayController(const struct TS3Functions funcs, quint64 se ...@@ -41,13 +42,7 @@ OverlayController::OverlayController(const struct TS3Functions funcs, quint64 se
m_SCHID = serverConnectionHandlerID; m_SCHID = serverConnectionHandlerID;
m_treeWidget = new QWidget; m_tree = new ChannelListWidget;
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);
} }
OverlayController::~OverlayController() OverlayController::~OverlayController()
...@@ -61,7 +56,7 @@ OverlayController::~OverlayController() ...@@ -61,7 +56,7 @@ OverlayController::~OverlayController()
m_msgLines.clear(); m_msgLines.clear();
delete m_debugWindow; delete m_debugWindow;
delete m_treeWidget; delete m_tree;
} }
void OverlayController::deleteChatLine(QWidget * line) void OverlayController::deleteChatLine(QWidget * line)
...@@ -210,7 +205,7 @@ void OverlayController::reset() ...@@ -210,7 +205,7 @@ void OverlayController::reset()
void OverlayController::updateChannelList() void OverlayController::updateChannelList()
{ {
if (m_treeWidget->isVisible()) if (m_tree->isVisible())
displayChannelList(); displayChannelList();
} }
...@@ -298,6 +293,5 @@ void OverlayController::displayChannelList() ...@@ -298,6 +293,5 @@ void OverlayController::displayChannelList()
m_tree->expandAll(); m_tree->expandAll();
connect(m_tree, &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked); connect(m_tree, &QTreeWidget::itemDoubleClicked, this, &OverlayController::treeItemClicked);
m_tree->adjustSize(); m_tree->adjustSize();
m_treeWidget->adjustSize(); m_tree->show();
m_treeWidget->show();
} }
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <QWidget> #include <QWidget>
#include <QVector> #include <QVector>
#include <QLabel> #include <QLabel>
#include <QTreeWidget> #include "ChannelListWidget.h"
#define MAXLINES 5 #define MAXLINES 5
...@@ -34,8 +34,7 @@ private: ...@@ -34,8 +34,7 @@ private:
QLabel* m_debugWindow; QLabel* m_debugWindow;
QVector<QWidget*> m_speakers; QVector<QWidget*> m_speakers;
QVector<QWidget*> m_msgLines; QVector<QWidget*> m_msgLines;
QTreeWidget* m_tree; ChannelListWidget* m_tree;
QWidget* m_treeWidget;
private: private:
void deleteChatLine(QWidget* line); void deleteChatLine(QWidget* line);
......
...@@ -102,8 +102,22 @@ QString channelID2Name(uint64 serverConnectionHandlerID, uint64 channelID) ...@@ -102,8 +102,22 @@ QString channelID2Name(uint64 serverConnectionHandlerID, uint64 channelID)
return name; 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); auto tmp = g_serverList.find(serverConnectionHandlerID);
if (tmp == g_serverList.end()) if (tmp == g_serverList.end())
...@@ -309,9 +323,7 @@ void ts3plugin_initHotkeys(struct PluginHotkey*** hotkeys) { ...@@ -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 keyword will be later passed to ts3plugin_onHotkeyEvent to identify which hotkey was triggered.
* The description is shown in the clients hotkey dialog. */ * The description is shown in the clients hotkey dialog. */
BEGIN_CREATE_HOTKEYS(3); /* Create 3 hotkeys. Size must be correct for allocating memory. */ BEGIN_CREATE_HOTKEYS(3); /* Create 3 hotkeys. Size must be correct for allocating memory. */
CREATE_HOTKEY("keyword_1", "Test hotkey 1"); CREATE_HOTKEY("Channellist", "Displays a simple channellist of the server");
CREATE_HOTKEY("keyword_2", "Test hotkey 2");
CREATE_HOTKEY("keyword_3", "Test hotkey 3");
END_CREATE_HOTKEYS; END_CREATE_HOTKEYS;
/* The client will call ts3plugin_freeMemory to release all allocated memory */ /* The client will call ts3plugin_freeMemory to release all allocated memory */
...@@ -400,13 +412,6 @@ void ts3plugin_onClientMoveEvent(uint64 serverConnectionHandlerID, anyID clientI ...@@ -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)); 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 ...@@ -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. */ /* This function is called if a plugin hotkey was pressed. Omit if hotkeys are unused. */
void ts3plugin_onHotkeyEvent(const char* keyword) { void ts3plugin_onHotkeyEvent(const char* keyword) {
printf("PLUGIN: Hotkey event: %s\n", 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 */ /* 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