From: hama Date: Mon, 25 May 2015 22:33:42 +0000 (+0200) Subject: new: appl/labor X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=cdcf121a60165cb70e4d12aa5b2c25e89252e339;p=reqt new: appl/labor --- diff --git a/.gitignore b/.gitignore index c6020b4..9a236de 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,8 @@ build-refind-Desktop_Qt_5_4_0_MSVC2010_OpenGL_32bit-Release/ .project *.pro.user.* +build-unittests-Desktop5-Debug/ +cunit/build-cunit-Desktop5-Debug/ +rpldoc.zip + +appl/labor/build-labor-Desktop5-Debug/ diff --git a/appl/labor/droptablewidget.cpp b/appl/labor/droptablewidget.cpp new file mode 100644 index 0000000..6b8efaa --- /dev/null +++ b/appl/labor/droptablewidget.cpp @@ -0,0 +1,79 @@ +/* + * 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 +#include +#include + +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 formats = mimeData->formats(); + QList::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 urls = mimeData->urls(); + m_mainWindow->log("url-list", "count=" + QString::number(urls.size())); + QList::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; +} + diff --git a/appl/labor/droptablewidget.hpp b/appl/labor/droptablewidget.hpp new file mode 100644 index 0000000..6c1f7d1 --- /dev/null +++ b/appl/labor/droptablewidget.hpp @@ -0,0 +1,31 @@ +/* + * 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 +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 diff --git a/appl/labor/labor.pro b/appl/labor/labor.pro new file mode 100644 index 0000000..17a10e2 --- /dev/null +++ b/appl/labor/labor.pro @@ -0,0 +1,22 @@ +#------------------------------------------------- +# +# 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 diff --git a/appl/labor/main.cpp b/appl/labor/main.cpp new file mode 100644 index 0000000..c5fb164 --- /dev/null +++ b/appl/labor/main.cpp @@ -0,0 +1,20 @@ +/* + * 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 + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/appl/labor/mainwindow.cpp b/appl/labor/mainwindow.cpp new file mode 100644 index 0000000..3f702e8 --- /dev/null +++ b/appl/labor/mainwindow.cpp @@ -0,0 +1,146 @@ +/* + * 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(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& urls){ + QByteArray rc; + rc.reserve(urls.length() * 80); + QList::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 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())); + } +} diff --git a/appl/labor/mainwindow.hpp b/appl/labor/mainwindow.hpp new file mode 100644 index 0000000..693f689 --- /dev/null +++ b/appl/labor/mainwindow.hpp @@ -0,0 +1,44 @@ +/* + * 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 +#include + +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 m_mimeData; +}; + +#endif // MAINWINDOW_HPP diff --git a/appl/labor/mainwindow.ui b/appl/labor/mainwindow.ui new file mode 100644 index 0000000..d1e8de1 --- /dev/null +++ b/appl/labor/mainwindow.ui @@ -0,0 +1,163 @@ + + + MainWindow + + + + 0 + 0 + 768 + 531 + + + + MainWindow + + + + + + + 0 + + + + Drag Info + + + + + + + + + + Drag anything into the following table to log the drag info: + + + + + + + true + + + 100 + + + true + + + + Drag No + + + + + Type + + + + + Content + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Clear + + + + + + + + + + + + Drag Data + + + + + + + + Data of the Last Drop Event: + + + + + + + + + + + + + + + + + + + + + 0 + 0 + 768 + 23 + + + + + + TopToolBarArea + + + false + + + + + + Clear + + + Delete all info lines + + + + + + + DropTableWidget + QTableWidget +
droptablewidget.hpp
+
+
+ + +