Skip to content
Snippets Groups Projects
Commit 22244587 authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

github -> gitlab migration

parents
No related branches found
No related tags found
No related merge requests found
v1.0: first release
This diff is collapsed.
### Adds a "Copy source" action to the right click menu of cumbia-qtcontrols widget supporting contextual menus
cumbia-qtcontrols widgets that use CuContextMenu to provide a right click menu will add a *Copy source* action
that copies the source (or target) of the widget into the *clipboard*.
The source (target) is copied as plain text.
To install the plugin, execute
- qmake
- make
- make install
after checking that the line
```
include(/usr/local/cumbia-libs/include/cumbia-qtcontrols/cumbia-qtcontrols.pri)
```
in the file cumbia-copy-source-context-menu-actions.pro is correct (in the default case,
cumbia-qtcontrols is installed under /usr/local/cumbia-libs)
Have fun.
{
"Keys" : [ ]
}
#-------------------------------------------------
#
# Project created by QtCreator 2019-09-03T15:28:56
#
#-------------------------------------------------
isEmpty(INSTALL_ROOT) {
INSTALL_ROOT = /usr/local/cumbia-libs
}
# INSTALL_ROOT is used to install the target
# prefix is used within DEFINES +=
#
# cumbia installation script uses a temporary INSTALL_ROOT during build
# and then files are copied into the destination prefix. That's where
# configuration files must be found by the application when the script
# installs everything at destination
#
isEmpty(prefix) {
prefix = $${INSTALL_ROOT}
}
include($${INSTALL_ROOT}/include/cumbia-qtcontrols/cumbia-qtcontrols.pri)
# Here qumbia-plugins libraries will be installed
QUMBIA_PLUGINS_LIBDIR=$${INSTALL_ROOT}/lib/qumbia-plugins
QT += core gui
TARGET = cumbia-copy-source-context-menu-actions
TEMPLATE = lib
CONFIG += plugin
isEmpty(buildtype) {
buildtype = release
} else {
equals(buildtype, debug) {
message("")
message("debug build")
message("")
}
}
CONFIG += $${buildtype}
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
src/cumbia-copy-source-ctx-menu-action.cpp
HEADERS += \
src/cumbia-copy-source-ctx-menu-action.h
DISTFILES += cumbia-copy-source-context-menu-actions.json \
README.md
unix {
target.path = $${QUMBIA_PLUGINS_LIBDIR}
INSTALLS += target
}
#include "cumbia-copy-source-ctx-menu-action.h"
#include <QClipboard>
#include <cucontrolsreader_abs.h>
#include <cucontrolswriter_abs.h>
#include <QApplication>
#include <cucontext.h>
#include <cucontexti.h>
CuCopySourceContextMenuActionPlugin::CuCopySourceContextMenuActionPlugin(QObject *parent) : QObject(parent)
{
m_ctxi = nullptr;
}
CuCopySourceContextMenuActionPlugin::~CuCopySourceContextMenuActionPlugin()
{
m_actions.clear();
}
void CuCopySourceContextMenuActionPlugin::setup(QWidget *widget, const CuContextI *cuctx)
{
Q_UNUSED(widget);
m_ctxi = cuctx;
if(m_actions.isEmpty()) {
QAction *a = new QAction("Copy source", this);
connect(a, SIGNAL(triggered()), this, SLOT(onActionTriggered()));
m_actions << a;
}
}
QList<QAction *> CuCopySourceContextMenuActionPlugin::getActions() const
{
return m_actions;
}
int CuCopySourceContextMenuActionPlugin::order() const
{
return 10;
}
void CuCopySourceContextMenuActionPlugin::onActionTriggered()
{
QClipboard *clipb = qApp->clipboard();
const CuContext *ctx = m_ctxi->getContext();
CuControlsWriterA *w = nullptr;
CuControlsReaderA* r = ctx->getReader();
if(r)
clipb->setText(r->source());
else if((w = ctx->getWriter()) != nullptr)
clipb->setText(w->target());
if(!r && !w)
perr("CuCopySourceContextMenuActionPlugin.onActionTriggered: neither a reader nor a writer are configured");
}
#ifndef CUMBIACOPYSOURCECTXMENUACTION_H
#define CUMBIACOPYSOURCECTXMENUACTION_H
#include <cucontextmenuactionsplugin_i.h>
#include <QAction>
#include <QList>
#include <QObject>
class CuCopySourceContextMenuActionPlugin : public QObject, public CuContextMenuActionsPlugin_I
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "cumbia-copy-source-context-menu-actions.json")
public:
explicit CuCopySourceContextMenuActionPlugin(QObject *parent = nullptr);
~CuCopySourceContextMenuActionPlugin();
Q_INTERFACES(CuContextMenuActionsPlugin_I)
// CuContextMenuActionsPlugin_I interface
public:
void setup(QWidget *widget, const CuContextI *cuctx);
QList<QAction *> getActions() const;
int order() const;
protected slots:
void onActionTriggered();
private:
QList<QAction *>m_actions;
const CuContextI *m_ctxi;
};
#endif // CUMBIACOPYSOURCECTXMENUACTION_H
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