Commit 426fa8ac authored by Christoffer Ackelman's avatar Christoffer Ackelman

QT: Changed selection to use the X11 selection clipboard.

parent aaf2e162
...@@ -152,7 +152,7 @@ else ...@@ -152,7 +152,7 @@ else
endif endif
explinkflags := $(cross_compile) -g -L$(elib_dir) explinkflags := $(cross_compile) -g -L$(elib_dir)
cxxflags := $(cflags) cxxflags := $(cflags) -Wno-deprecated-copy
clis = /lis=$(list) clis = /lis=$(list)
dolist = /lis=$(list) dolist = /lis=$(list)
domap = -Xlinker -Map -Xlinker $(map) domap = -Xlinker -Map -Xlinker $(map)
......
...@@ -1277,10 +1277,5 @@ int WFoeQt::view_set_entries() ...@@ -1277,10 +1277,5 @@ int WFoeQt::view_set_entries()
int WFoeQt::get_selection(char* str, int len) int WFoeQt::get_selection(char* str, int len)
{ {
int sts = CoWowQt::GetSelection(str, len, "PWR_OBJID"); return CoWowQt::GetSelection(str, len);
if (EVEN(sts)) {
sts = CoWowQt::GetSelection(str, len, "STRING");
}
return sts;
} }
...@@ -42,26 +42,20 @@ ...@@ -42,26 +42,20 @@
#include "wb_nav_qt.h" #include "wb_nav_qt.h"
#include <QApplication>
#include <QClipboard>
#include <QScrollArea> #include <QScrollArea>
#include <qlocalsocket.h>
NavQt::NavQt(void* nav_parent_ctx, const char* nav_name, NavQt::NavQt(void* nav_parent_ctx, const char* nav_name,
ldh_tSesContext nav_ldhses, const char* nav_root_name, QWidget** w, ldh_tSesContext nav_ldhses, const char* nav_root_name, QWidget** w,
pwr_tStatus* status) pwr_tStatus* status)
: Nav(nav_parent_ctx, nav_name, nav_ldhses, nav_root_name, status) : Nav(nav_parent_ctx, nav_name, nav_ldhses, nav_root_name, status)
{ {
trace_obj = new NavQtTraceObject(this);
QScrollArea* scrolledbrow = ((QScrollArea*)scrolledbrowwidgetqt_new( QScrollArea* scrolledbrow = ((QScrollArea*)scrolledbrowwidgetqt_new(
Nav::init_brow_cb, this, &brow_widget)); Nav::init_brow_cb, this, &brow_widget));
form_widget = wrapInFrame(scrolledbrow); form_widget = wrapInFrame(scrolledbrow);
server = new QLocalServer(trace_obj);
QObject::connect(
server, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
set_inputfocus(0); set_inputfocus(0);
*w = form_widget; *w = form_widget;
...@@ -72,45 +66,27 @@ NavQt::~NavQt() ...@@ -72,45 +66,27 @@ NavQt::~NavQt()
{ {
PalFile::config_tree_free(menu); PalFile::config_tree_free(menu);
free_pixmaps(); free_pixmaps();
delete trace_obj;
form_widget->close(); form_widget->close();
} }
void NavQtTraceObject::sel_convert_cb() void NavQt::set_selection_owner(int set)
{ {
char name[200]; selection_owner = set;
pwr_tStatus sts; if (!selection_owner) {
if (!nav->selection_owner) {
return; return;
} }
if (!nav->get_plant_select_cb) { char name[200];
if (!get_plant_select_cb) {
strcpy(name, ""); strcpy(name, "");
} else { } else {
sts = nav->get_plant_select_cb(nav->parent_ctx, name, sizeof(name)); pwr_tStatus sts = get_plant_select_cb(parent_ctx, name, sizeof(name));
if (EVEN(sts)) { if (EVEN(sts)) {
strcpy(name, ""); strcpy(name, "");
} }
} }
QByteArray block; QApplication::clipboard()->setText(name, QClipboard::Selection);
QDataStream out(&block, QIODevice::WriteOnly);
out.writeRawData(name, strlen(name));
QLocalSocket* clientConnection = nav->server->nextPendingConnection();
clientConnection->write(block);
clientConnection->flush();
clientConnection->disconnectFromServer();
}
void NavQt::set_selection_owner(int set)
{
if (!server->isListening()) {
QLocalServer::removeServer("STRING");
server->listen("STRING");
}
selection_owner = set;
} }
static void modifyBackground(QWidget* widget, QColor color) static void modifyBackground(QWidget* widget, QColor color)
......
...@@ -43,10 +43,6 @@ ...@@ -43,10 +43,6 @@
#include <QWidget> #include <QWidget>
#include <qlocalserver.h>
class NavQtTraceObject;
class NavQt : public Nav { class NavQt : public Nav {
public: public:
NavQt(void* parent_ctx, const char* name, ldh_tSesContext ldhses, NavQt(void* parent_ctx, const char* name, ldh_tSesContext ldhses,
...@@ -56,26 +52,8 @@ public: ...@@ -56,26 +52,8 @@ public:
QWidget* brow_widget; QWidget* brow_widget;
QWidget* form_widget; QWidget* form_widget;
QLocalServer* server;
void set_inputfocus(int focus); void set_inputfocus(int focus);
void set_selection_owner(int set); void set_selection_owner(int set);
private:
NavQtTraceObject* trace_obj;
};
class NavQtTraceObject : public QObject {
Q_OBJECT
public:
NavQtTraceObject(NavQt* parent) : QObject(), nav(parent) {}
public slots:
void sel_convert_cb();
private:
NavQt* nav;
}; };
#endif #endif
...@@ -42,26 +42,20 @@ ...@@ -42,26 +42,20 @@
#include "wb_pal_qt.h" #include "wb_pal_qt.h"
#include <QApplication>
#include <QClipboard>
#include <QScrollArea> #include <QScrollArea>
#include <qlocalsocket.h>
PalQt::PalQt(void* pal_parent_ctx, const char* pal_name, PalQt::PalQt(void* pal_parent_ctx, const char* pal_name,
ldh_tSesContext pal_ldhses, const char* pal_root_name, QWidget** w, ldh_tSesContext pal_ldhses, const char* pal_root_name, QWidget** w,
pwr_tStatus* status) pwr_tStatus* status)
: Pal(pal_parent_ctx, pal_name, pal_ldhses, pal_root_name, status) : Pal(pal_parent_ctx, pal_name, pal_ldhses, pal_root_name, status)
{ {
trace_obj = new PalQtTraceObject(this);
QScrollArea* scrolledbrow = ((QScrollArea*)scrolledbrowwidgetqt_new( QScrollArea* scrolledbrow = ((QScrollArea*)scrolledbrowwidgetqt_new(
Pal::init_brow_cb, this, &brow_widget)); Pal::init_brow_cb, this, &brow_widget));
form_widget = wrapInFrame(scrolledbrow); form_widget = wrapInFrame(scrolledbrow);
server = new QLocalServer(trace_obj);
QObject::connect(
server, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
set_inputfocus(0); set_inputfocus(0);
*w = form_widget; *w = form_widget;
...@@ -70,7 +64,6 @@ PalQt::PalQt(void* pal_parent_ctx, const char* pal_name, ...@@ -70,7 +64,6 @@ PalQt::PalQt(void* pal_parent_ctx, const char* pal_name,
PalQt::~PalQt() PalQt::~PalQt()
{ {
delete trace_obj;
PalFile::config_tree_free(menu); PalFile::config_tree_free(menu);
free_pixmaps(); free_pixmaps();
form_widget->close(); form_widget->close();
...@@ -107,25 +100,16 @@ void PalQt::set_inputfocus(int focus) ...@@ -107,25 +100,16 @@ void PalQt::set_inputfocus(int focus)
void PalQt::set_selection_owner() void PalQt::set_selection_owner()
{ {
if (!server->isListening()) {
QLocalServer::removeServer("STRING");
server->listen("STRING");
}
selection_owner = 1; selection_owner = 1;
brow_SetInverseColor(brow_ctx, flow_eDrawType_Line); brow_SetInverseColor(brow_ctx, flow_eDrawType_Line);
} if (!selection_owner) {
return;
}
void PalQtTraceObject::sel_convert_cb()
{
char name[200]; char name[200];
brow_tNode* node_list; brow_tNode* node_list;
int node_count; int node_count;
brow_GetSelectedNodes(brow_ctx, &node_list, &node_count);
if (!pal->selection_owner) {
return;
}
brow_GetSelectedNodes(pal->brow_ctx, &node_list, &node_count);
if (!node_count) { if (!node_count) {
strcpy(name, ""); strcpy(name, "");
} else { } else {
...@@ -142,12 +126,5 @@ void PalQtTraceObject::sel_convert_cb() ...@@ -142,12 +126,5 @@ void PalQtTraceObject::sel_convert_cb()
} }
} }
QByteArray block; QApplication::clipboard()->setText(name, QClipboard::Selection);
QDataStream out(&block, QIODevice::WriteOnly);
out.writeRawData(name, strlen(name));
QLocalSocket* clientConnection = pal->server->nextPendingConnection();
clientConnection->write(block);
clientConnection->flush();
clientConnection->disconnectFromServer();
} }
...@@ -41,10 +41,6 @@ ...@@ -41,10 +41,6 @@
#include <QWidget> #include <QWidget>
#include <qlocalserver.h>
class PalQtTraceObject;
class PalQt : public Pal { class PalQt : public Pal {
public: public:
PalQt(void* parent_ctx, const char* name, ldh_tSesContext ldhses, PalQt(void* parent_ctx, const char* name, ldh_tSesContext ldhses,
...@@ -54,27 +50,9 @@ public: ...@@ -54,27 +50,9 @@ public:
QWidget* brow_widget; QWidget* brow_widget;
QWidget* form_widget; QWidget* form_widget;
QLocalServer* server;
void set_inputfocus(int focus); void set_inputfocus(int focus);
void set_selection_owner(); void set_selection_owner();
void create_popup_menu(pwr_tCid cid, int x, int y); void create_popup_menu(pwr_tCid cid, int x, int y);
private:
PalQtTraceObject* trace_obj;
};
class PalQtTraceObject : public QObject {
Q_OBJECT
public:
PalQtTraceObject(PalQt* parent) : QObject(), pal(parent) {}
public slots:
void sel_convert_cb();
private:
PalQt* pal;
}; };
#endif #endif
...@@ -66,11 +66,7 @@ WAttNavQt::~WAttNavQt() ...@@ -66,11 +66,7 @@ WAttNavQt::~WAttNavQt()
pwr_tStatus WAttNavQt::get_selection(char* str, int size) pwr_tStatus WAttNavQt::get_selection(char* str, int size)
{ {
pwr_tStatus sts = CoWowQt::GetSelection(str, size, "PWR_OBJID"); return CoWowQt::GetSelection(str, size);
if (EVEN(sts)) {
sts = CoWowQt::GetSelection(str, size, "STRING");
}
return sts;
} }
void WAttNavQt::set_inputfocus() void WAttNavQt::set_inputfocus()
......
...@@ -60,14 +60,13 @@ ...@@ -60,14 +60,13 @@
#include "wb_xcrr_qt.h" #include "wb_xcrr_qt.h"
#include <QApplication> #include <QApplication>
#include <QClipboard>
#include <QColor> #include <QColor>
#include <QInputDialog> #include <QInputDialog>
#include <QLayout> #include <QLayout>
#include <QMessageBox> #include <QMessageBox>
#include <QScrollArea> #include <QScrollArea>
#include <qlocalsocket.h>
void WNavQt::pop() void WNavQt::pop()
{ {
::pop(form_widget); ::pop(form_widget);
...@@ -94,19 +93,6 @@ WNavQt::WNavQt(void* xn_parent_ctx, QWidget* xn_parent_wid, const char* xn_name, ...@@ -94,19 +93,6 @@ WNavQt::WNavQt(void* xn_parent_ctx, QWidget* xn_parent_wid, const char* xn_name,
// Create the root item // Create the root item
*w = form_widget; *w = form_widget;
serverString = new QLocalServer(trace_obj);
QObject::connect(
serverString, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
serverGraph = new QLocalServer(trace_obj);
QObject::connect(
serverGraph, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
serverObjId = new QLocalServer(trace_obj);
QObject::connect(
serverObjId, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
serverAttrRef = new QLocalServer(trace_obj);
QObject::connect(serverAttrRef, SIGNAL(newConnection()), trace_obj,
SLOT(sel_convert_cb()));
gbl.load_config(this); gbl.load_config(this);
if (root_menu && !ldhses) { if (root_menu && !ldhses) {
...@@ -181,36 +167,79 @@ void WNavQt::print(const char* title) ...@@ -181,36 +167,79 @@ void WNavQt::print(const char* title)
int WNavQt::get_selection(char* str, int len) int WNavQt::get_selection(char* str, int len)
{ {
int sts; return CoWowQt::GetSelection(str, len);
sts = CoWowQt::GetSelection(str, len, "PWR_OBJID");
if (EVEN(sts)) {
sts = CoWowQt::GetSelection(str, len, "STRING");
}
return sts;
} }
void WNavQt::set_selection_owner() void WNavQt::set_selection_owner()
{ {
if (!serverString->isListening()) { selection_owner = 1;
QLocalServer::removeServer("STRING"); if (!selection_owner) {
serverString->listen("STRING"); return;
}
if (!serverGraph->isListening()) {
QLocalServer::removeServer("PWR_GRAPH");
serverGraph->listen("PWR_GRAPH");
} }
if (!serverObjId->isListening()) {
QLocalServer::removeServer("PWR_OBJID"); pwr_sAttrRef attrref;
serverObjId->listen("PWR_OBJID"); char* buffp;
int node_count;
brow_tNode* node_list;
brow_GetSelectedNodes(brow->ctx, &node_list, &node_count);
if (!node_count) {
return;
} }
if (!serverAttrRef->isListening()) {
QLocalServer::removeServer("PWR_ATTRREF"); WItem* item;
serverAttrRef->listen("PWR_ATTRREF"); brow_GetUserData(node_list[0], (void**)&item);
switch (item->type) {
case wnav_eItemType_Attr:
case wnav_eItemType_AttrInput:
case wnav_eItemType_AttrInputInv:
case wnav_eItemType_AttrInputF:
case wnav_eItemType_AttrOutput:
case wnav_eItemType_AttrArray:
case wnav_eItemType_AttrArrayOutput:
case wnav_eItemType_AttrArrayElem:
case wnav_eItemType_AttrObject: {
WItemBaseAttr* aitem = (WItemBaseAttr*)item;
int size;
pwr_tAName attr_str;
int sts = ldh_ObjidToName(ldhses, item->objid, ldh_eName_Hierarchy,
attr_str, sizeof(attr_str), &size);
if (EVEN(sts)) {
break;
} }
selection_owner = 1; strcat(attr_str, ".");
strcat(attr_str, aitem->name);
sts = ldh_NameToAttrRef(ldhses, attr_str, &attrref);
if (EVEN(sts)) {
break;
}
sts = (format_selection_cb)(
parent_ctx, attrref, &buffp, 0, 1, wnav_eSelectionFormat_User);
if (sts) {
QApplication::clipboard()->setText(buffp, QClipboard::Selection);
}
break;
}
case wnav_eItemType_Object: {
attrref = cdh_ObjidToAref(item->objid);
int sts = (format_selection_cb)(
parent_ctx, attrref, &buffp, 0, 0, wnav_eSelectionFormat_User);
if (sts) {
QApplication::clipboard()->setText(buffp, QClipboard::Selection);
}
break;
}
default: {
char name[200];
brow_GetAnnotation(node_list[0], 0, name, sizeof(name));
QApplication::clipboard()->setText(name, QClipboard::Selection);
break;
}
}
free(node_list);
} }
void WNavQt::create_popup_menu(pwr_tAttrRef aref, int x, int y) void WNavQt::create_popup_menu(pwr_tAttrRef aref, int x, int y)
...@@ -282,101 +311,6 @@ void WNavQt::logw_new(char* item, wlog_eCategory* categories, int show_item) ...@@ -282,101 +311,6 @@ void WNavQt::logw_new(char* item, wlog_eCategory* categories, int show_item)
} }
} }
static void selection_data_set(
WNavQt* wnav, QLocalServer* server, const char* data)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << QString(data);
QLocalSocket* clientConnection = server->nextPendingConnection();
QObject::connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));
clientConnection->write(block);
clientConnection->flush();
clientConnection->disconnectFromServer();
}
void WNavQtTraceObject::sel_convert_cb()
{
pwr_sAttrRef attrref;
char* buffp;
QLocalServer* server = ((QLocalServer*)sender());
wnav_eSelectionFormat format;
if (server == wnav->serverGraph) {
format = wnav_eSelectionFormat_Graph;
} else if (server == wnav->serverObjId) {
format = wnav_eSelectionFormat_Objid;
} else if (server == wnav->serverAttrRef) {
format = wnav_eSelectionFormat_Attrref;
} else {
format = wnav_eSelectionFormat_User;
}
int node_count;
brow_tNode* node_list;
brow_GetSelectedNodes(wnav->brow->ctx, &node_list, &node_count);
if (!node_count) {
return;
}
WItem* item;
brow_GetUserData(node_list[0], (void**)&item);
switch (item->type) {
case wnav_eItemType_Attr:
case wnav_eItemType_AttrInput:
case wnav_eItemType_AttrInputInv:
case wnav_eItemType_AttrInputF:
case wnav_eItemType_AttrOutput:
case wnav_eItemType_AttrArray:
case wnav_eItemType_AttrArrayOutput:
case wnav_eItemType_AttrArrayElem:
case wnav_eItemType_AttrObject: {
WItemBaseAttr* aitem = (WItemBaseAttr*)item;
int size;
pwr_tAName attr_str;
int sts = ldh_ObjidToName(wnav->ldhses, item->objid, ldh_eName_Hierarchy,
attr_str, sizeof(attr_str), &size);
if (EVEN(sts)) {
break;
}
strcat(attr_str, ".");
strcat(attr_str, aitem->name);
sts = ldh_NameToAttrRef(wnav->ldhses, attr_str, &attrref);
if (EVEN(sts)) {
break;
}
sts = (wnav->format_selection_cb)(
wnav->parent_ctx, attrref, &buffp, 0, 1, format);
if (sts) {
selection_data_set(wnav, server, buffp);
}
break;
}
case wnav_eItemType_Object: {
attrref = cdh_ObjidToAref(item->objid);
int sts = (wnav->format_selection_cb)(
wnav->parent_ctx, attrref, &buffp, 0, 0, format);
if (sts) {
selection_data_set(wnav, server, buffp);
}
break;
}
default: {
char name[200];
brow_GetAnnotation(node_list[0], 0, name, sizeof(name));
selection_data_set(wnav, server, name);
break;
}
}
free(node_list);
}
int WNavQt::open_foe(const char* name, pwr_tOid plcpgm, void** foectx, int WNavQt::open_foe(const char* name, pwr_tOid plcpgm, void** foectx,
int map_window, ldh_eAccess access, pwr_tOid oid) int map_window, ldh_eAccess access, pwr_tOid oid)
{ {
......
...@@ -41,8 +41,6 @@ ...@@ -41,8 +41,6 @@
#include <QTimer> #include <QTimer>
#include <qlocalserver.h>
/* wtt_wnav_qt.h -- Simple navigator */ /* wtt_wnav_qt.h -- Simple navigator */
class CoLogin; class CoLogin;
...@@ -62,11 +60,6 @@ public: ...@@ -62,11 +60,6 @@ public:
QWidget* brow_widget; QWidget* brow_widget;
QWidget* form_widget; QWidget* form_widget;
QLocalServer* serverString;
QLocalServer* serverGraph;
QLocalServer* serverObjId;
QLocalServer* serverAttrRef;
void pop(); void pop();
void set_inputfocus(int focus); void set_inputfocus(int focus);
void print(const char* title); void print(const char* title);
...@@ -115,7 +108,6 @@ public: ...@@ -115,7 +108,6 @@ public:
public slots: public slots:
void trace_scan(); void trace_scan();
void sel_convert_cb();
private: private:
WNavQt* wnav; WNavQt* wnav;
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "flow_browapi.h" #include "flow_browapi.h"
#include <QApplication> #include <QApplication>
#include <QClipboard>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QFileDialog> #include <QFileDialog>
#include <QHBoxLayout> #include <QHBoxLayout>
...@@ -70,8 +71,6 @@ ...@@ -70,8 +71,6 @@
#include <QTimer> #include <QTimer>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <qlocalsocket.h>
typedef struct { typedef struct {
char title[80]; char title[80];
flow_tCtx flow_ctx; flow_tCtx flow_ctx;
...@@ -413,34 +412,13 @@ void CoWowQtObject::DisplayLicense() ...@@ -413,34 +412,13 @@ void CoWowQtObject::DisplayLicense()
pop(mbox); pop(mbox);
} }
int CoWowQt::GetSelection(char* str, int size, const char* atom) int CoWowQt::GetSelection(char* str, int size)
{ {
QLocalSocket* socket = new QLocalSocket(); QString rcvStr = QApplication::clipboard()->text(QClipboard::Selection);
socket->connectToServer(fl(atom));
if (!socket->waitForConnected()) {
log_debug("GetSelection failed, could not connect to local server %s: %s\n", fl(atom), qPrintable(socket->errorString()));
}
QString rcvStr;
int received = 0;
while (!received) {
if (socket->waitForReadyRead(50)) {
QDataStream in(socket);
if (socket->bytesAvailable() > 0 && !in.atEnd()) {
in >> rcvStr;
}
received = 1;
}
QApplication::processEvents();
}
socket->close();
delete socket;
if (!rcvStr.isEmpty() && rcvStr.length() < size) { if (!rcvStr.isEmpty() && rcvStr.length() < size) {
strcpy(str, qPrintable(rcvStr)); strcpy(str, qPrintable(rcvStr));
return true;
} }
return !rcvStr.isEmpty(); return !rcvStr.isEmpty();
} }
......
...@@ -223,7 +223,7 @@ public: ...@@ -223,7 +223,7 @@ public:
static void PopupPosition( static void PopupPosition(
QWidget* parent, int x_event, int y_event, int* x, int* y); QWidget* parent, int x_event, int y_event, int* x, int* y);
static int GetSelection(char* str, int size, const char* atom); static int GetSelection(char* str, int size);
static void SetWindowIcon(QWidget* w); static void SetWindowIcon(QWidget* w);
static void update_title(QWidget* w, int editmode); static void update_title(QWidget* w, int editmode);
......
...@@ -320,14 +320,9 @@ int GeQt::get_plant_select(char* select_name, int size) ...@@ -320,14 +320,9 @@ int GeQt::get_plant_select(char* select_name, int size)
pwr_tAName buff; pwr_tAName buff;
if (!ldhses) { if (!ldhses) {
sts = CoWowQt::GetSelection(str, sizeof(str), "PWR_GRAPH"); sts = CoWowQt::GetSelection(str, sizeof(str));
if (ODD(sts)) { if (ODD(sts)) {
strcpy(select_name, str); strcpy(select_name, str);
} else {
sts = CoWowQt::GetSelection(str, sizeof(str), "STRING");
if (ODD(sts)) {
strcpy(select_name, str);
}
} }
return sts; return sts;
} }
...@@ -342,14 +337,9 @@ int GeQt::get_plant_select(char* select_name, int size) ...@@ -342,14 +337,9 @@ int GeQt::get_plant_select(char* select_name, int size)
strncpy(select_name, buff, size); strncpy(select_name, buff, size);
return 1; return 1;
} else { } else {
sts = CoWowQt::GetSelection(str, sizeof(str), "PWR_GRAPH"); sts = CoWowQt::GetSelection(str, sizeof(str));
if (ODD(sts)) { if (ODD(sts)) {
strncpy(select_name, str, size); strncpy(select_name, str, size);
} else {
sts = CoWowQt::GetSelection(str, sizeof(str), "STRING");
if (ODD(sts)) {
strncpy(select_name, str, size);
}
} }
return sts; return sts;
} }
......
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