.project
*.pro.user.*
+build-unittests-Desktop5-Debug/
+cunit/build-cunit-Desktop5-Debug/
+rpldoc.zip
+
+appl/labor/build-labor-Desktop5-Debug/
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+#include "mainwindow.hpp"
+#include "droptablewidget.hpp"
+#include <QEvent>
+#include <QDragEnterEvent>
+#include <QMimeData>
+
+DropTableWidget::DropTableWidget(QWidget* parent) :
+ QTableWidget(parent),
+ m_mainWindow(NULL)
+{
+}
+#if 1
+void DropTableWidget::dragEnterEvent(QDragEnterEvent *event)
+{
+ event->acceptProposedAction();
+}
+
+void DropTableWidget::dragMoveEvent(QDragMoveEvent *event)
+{
+ event->acceptProposedAction();
+}
+void DropTableWidget::dragLeaveEvent(QDragLeaveEvent *event)
+{
+ event->accept();
+}
+#endif
+
+QString headOf(const QString& text){
+ QString rc;
+ if (text.length() > 2000)
+ rc = text.mid(0, 2000) + "...";
+ else
+ rc = text;
+ return rc;
+}
+
+void DropTableWidget::dropEvent(QDropEvent *event)
+{
+ const QMimeData *mimeData = event->mimeData();
+ m_mainWindow->nextDrop();
+ QList<QString> formats = mimeData->formats();
+ QList<QString>::const_iterator it;
+ for (it = formats.begin(); it != formats.end(); ++it){
+ m_mainWindow->log("format", *it);
+ }
+ if (mimeData->hasImage()) {
+ m_mainWindow->log("image", NULL);
+ }
+ if (mimeData->hasHtml()) {
+ m_mainWindow->log("html", headOf(mimeData->html()));
+ }
+ if (mimeData->hasText()) {
+ m_mainWindow->log("text", headOf(mimeData->text()));
+ }
+ if (mimeData->hasUrls()) {
+ QList<QUrl> urls = mimeData->urls();
+ m_mainWindow->log("url-list", "count=" + QString::number(urls.size()));
+ QList<QUrl>::const_iterator it;
+ int count = 0;
+ for (it = urls.begin(); count++ < 3 && it != urls.end(); ++it)
+ m_mainWindow->log("url", (*it).path());
+ }
+ m_mainWindow->setMimeData(mimeData);
+ event->acceptProposedAction();
+}
+
+void DropTableWidget::setMainWindow(MainWindow* mainWindow)
+{
+ m_mainWindow = mainWindow;
+}
+
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+
+#ifndef DROPTABLEWIDGET_HPP
+#define DROPTABLEWIDGET_HPP
+#include <QTableWidget>
+class DropTableWidget : public QTableWidget
+{
+public:
+ DropTableWidget(QWidget* widget);
+protected:
+#if 1
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dragLeaveEvent(QDragLeaveEvent *event);
+ void dragMoveEvent(QDragMoveEvent *event);
+#endif
+ void dropEvent(QDropEvent *event);
+public:
+ void setMainWindow(MainWindow* mainWindow);
+
+private:
+ MainWindow* m_mainWindow;
+};
+
+#endif // DROPTABLEWIDGET_HPP
--- /dev/null
+#-------------------------------------------------
+#
+# Project created by QtCreator 2015-05-25T16:13:43
+#
+#-------------------------------------------------
+
+QT += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = labor
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+ mainwindow.cpp \
+ droptablewidget.cpp
+
+HEADERS += mainwindow.hpp \
+ droptablewidget.hpp
+
+FORMS += mainwindow.ui
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+
+#include "mainwindow.hpp"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+
+ return a.exec();
+}
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+
+#include "mainwindow.hpp"
+#include "ui_mainwindow.h"
+
+enum {
+ COL_NO,
+ COL_TYPE,
+ COL_CONTENT
+};
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow),
+ m_dropNo(0)
+{
+ ui->setupUi(this);
+ ui->tableWidgetDragInfo->setMainWindow(this);
+ connect(ui->comboBoxMimeType, SIGNAL(currentIndexChanged(const QString&)),
+ this, SLOT(currentIndexChanged(const QString&)));
+
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::log(const QString& type, const QString& data)
+{
+ ui->tableWidgetDragInfo->insertRow(0);
+ ui->tableWidgetDragInfo->setItem(0, COL_NO, new QTableWidgetItem(QString::number(m_dropNo)));
+ ui->tableWidgetDragInfo->setItem(0, COL_TYPE, new QTableWidgetItem(type));
+ ui->tableWidgetDragInfo->setItem(0, COL_CONTENT, new QTableWidgetItem(data));
+}
+
+bool MainWindow::isBinary(const QByteArray& data)
+{
+ bool rc = false;
+ for (int ix = 0; ix < data.length(); ix++){
+ if (data.at(ix) == 0){
+ rc = true;
+ break;
+ }
+ }
+ return rc;
+}
+
+double MainWindow::fontWidth(){
+ QFont myFont;
+ QString str("0005: 61 62 63 64 65 66 67 68 69 6a|abcdefghijk");
+
+ QFontMetrics fm(myFont);
+ double width = fm.width(str) / str.length();
+ return width;
+}
+inline char toHex(int value){
+ return value < 10 ? '0' + value : 'a' + (value - 10);
+}
+
+void MainWindow::setData(const char* data, int dataSize, int lineLength)
+{
+ if (lineLength < 0)
+ lineLength = int (ui->plainTextEdit->width() / fontWidth()) - 1;
+ int offsetWidth = dataSize >= 1000*1000 ? 10 : dataSize > 10000 ? 6 : 4;
+ int charPerLine = (lineLength - offsetWidth - 1) / 4;
+ int countLines = (dataSize + charPerLine - 1) / charPerLine;
+ int restLength = dataSize;
+ char formatOffset[10];
+ snprintf(formatOffset, sizeof formatOffset, "%%0%dd:", offsetWidth);
+ const unsigned char* ptr = reinterpret_cast<const unsigned char*>(data);
+ QByteArray buffer;
+ buffer.reserve(countLines * (charPerLine + 1) + 100);
+ char lineNo[32];
+ int offset = 0;
+ while (restLength > 0){
+ snprintf(lineNo, sizeof lineNo, formatOffset, offset);
+ buffer.append(lineNo);
+ for (int ix = 0; ix < charPerLine; ix++){
+ if (ix >= restLength)
+ buffer.append(" ");
+ else
+ buffer.append(toHex(ptr[ix]/16)).append(toHex(ptr[ix]%16)).append(' ');
+ }
+ buffer[buffer.length() - 1] = '|';
+ for (int ix = 0; ix < charPerLine; ix++){
+ if (ix >= restLength)
+ buffer.append(" ");
+ else if (ptr[ix] > 0x7f || ptr[ix] < ' ')
+ buffer.append('.');
+ else
+ buffer.append((char) ptr[ix]);
+ }
+ buffer.append('\n');
+ restLength -= charPerLine;
+ ptr += charPerLine;
+ offset += charPerLine;
+ }
+ ui->plainTextEdit->setPlainText(QString::fromUtf8(buffer));
+}
+
+QByteArray urlAsBytes(const QList<QUrl>& urls){
+ QByteArray rc;
+ rc.reserve(urls.length() * 80);
+ QList<QUrl>::const_iterator it;
+ for (it = urls.begin(); it != urls.end(); ++it){
+ rc.append(it->path()).append('\n');
+ }
+ return rc;
+}
+
+void MainWindow::setMimeData(const QMimeData* mime){
+ m_mimeData.clear();
+ QList<QString> formats = mime->formats();
+ ui->comboBoxMimeType->clear();
+ ui->comboBoxMimeType->addItems(formats);
+ for (int ix = 0; ix < formats.length(); ix++){
+ QString name = formats.at(ix);
+ if (name.indexOf("html") >= 0)
+ m_mimeData[name] = mime->html().toUtf8();
+ else if (name.indexOf("text") >= 0)
+ m_mimeData[name] = mime->text().toUtf8();
+ else if (name.indexOf("image") >= 0)
+ m_mimeData[name] = mime->imageData().toByteArray();
+ else if (name.indexOf("uri-list") >= 0)
+ m_mimeData[name] = urlAsBytes(mime->urls());
+ else
+ m_mimeData[name] = mime->data(name);
+ }
+}
+
+void MainWindow::currentIndexChanged(const QString& text)
+{
+ QByteArray data = m_mimeData[text];
+ if (isBinary(data)){
+ setData(data.constData(), data.length());
+ } else {
+ ui->plainTextEdit->setPlainText(QString::fromUtf8(data.constData()));
+ }
+}
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+
+#ifndef MAINWINDOW_HPP
+#define MAINWINDOW_HPP
+
+#include <QMainWindow>
+#include <QMimeData>
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+public:
+ double fontWidth();
+ void log(const QString& type, const QString& data);
+ void nextDrop(){
+ m_dropNo++;
+ }
+ bool isBinary(const QByteArray& data);
+ void setData(const char* data, int dataSize, int lineLength = -1);
+ void setMimeData(const QMimeData* data);
+private slots:
+ void currentIndexChanged(const QString& text);
+private:
+ Ui::MainWindow *ui;
+ int m_dropNo;
+ QMap<QString, QByteArray> m_mimeData;
+};
+
+#endif // MAINWINDOW_HPP
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>768</width>
+ <height>531</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>Drag Info</string>
+ </attribute>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Drag anything into the following table to log the drag info:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="DropTableWidget" name="tableWidgetDragInfo">
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
+ <attribute name="horizontalHeaderDefaultSectionSize">
+ <number>100</number>
+ </attribute>
+ <attribute name="horizontalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>Drag No</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Type</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Content</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonClear">
+ <property name="text">
+ <string>Clear</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_2">
+ <attribute name="title">
+ <string>Drag Data</string>
+ </attribute>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Data of the Last Drop Event:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="comboBoxMimeType"/>
+ </item>
+ <item>
+ <widget class="QPlainTextEdit" name="plainTextEdit"/>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>768</width>
+ <height>23</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <action name="actionClear">
+ <property name="text">
+ <string>Clear</string>
+ </property>
+ <property name="toolTip">
+ <string>Delete all info lines</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>DropTableWidget</class>
+ <extends>QTableWidget</extends>
+ <header>droptablewidget.hpp</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>