Add usage hints

This commit is contained in:
ArsenArsen 2017-07-09 21:04:21 +02:00
parent 0dd4a40adc
commit e090389201
16 changed files with 69 additions and 32 deletions

View File

@ -7,5 +7,4 @@ before_install:
script: script:
- cd build - cd build
- qmake .. - qmake ..
- make -j4 - make -j$(($(nproc) + 1))

View File

@ -19,7 +19,7 @@ build_script:
- xcopy ffmpeg-3.3.2-win64-dev\* %QTDIR% /e /i /Y - xcopy ffmpeg-3.3.2-win64-dev\* %QTDIR% /e /i /Y
- xcopy QtAV-depends-windows-x86+x64\* %QTDIR% /e /i /Y - xcopy QtAV-depends-windows-x86+x64\* %QTDIR% /e /i /Y
- qmake CONFIG+=nopkg ../KShare.pro - qmake CONFIG+=nopkg ../KShare.pro
- mingw32-make.exe -j8 - mingw32-make.exe -j%NUMBER_OF_PROCESSORS%
- copy release\KShare.exe ..\KShare.exe - copy release\KShare.exe ..\KShare.exe
- cd .. - cd ..
- bash AppVeyor\make_installer.sh - bash AppVeyor\make_installer.sh

View File

@ -135,19 +135,19 @@ nopkg {
} }
mac { mac {
ICON = icons/icon.icns ICON = $$PWD/icons/icon.icns
SOURCES += $$PWD/platformspecifics/mac/macbackend.cpp SOURCES += $$PWD/platformspecifics/mac/macbackend.cpp
HEADERS += $$PWD/platformspecifics/mac/macbackend.hpp HEADERS += $$PWD/platformspecifics/mac/macbackend.hpp
LIBS += -framework Carbon LIBS += -framework Carbon
warning(Mac is on TODO); warning(Mac is on TODO);
} else:win32 { } else:win32 {
RC_FILE = icon.rc RC_FILE = $$PWD/icon.rc
SOURCES += $$PWD/platformspecifics/u32/u32backend.cpp SOURCES += $$PWD/platformspecifics/u32/u32backend.cpp
HEADERS += $$PWD/platformspecifics/u32/u32backend.hpp HEADERS += $$PWD/platformspecifics/u32/u32backend.hpp
LIBS += -luser32 -lkernel32 -lpthread LIBS += -luser32 -lkernel32 -lpthread
QT += winextras QT += winextras
} else:unix { } else:unix {
RC_FILE = icon.rc RC_FILE = $$PWD/icon.rc
SOURCES += $$PWD/platformspecifics/x11/x11backend.cpp SOURCES += $$PWD/platformspecifics/x11/x11backend.cpp
HEADERS += $$PWD/platformspecifics/x11/x11backend.hpp HEADERS += $$PWD/platformspecifics/x11/x11backend.hpp
QT += x11extras QT += x11extras

View File

@ -3,7 +3,7 @@ A [ShareX](https://getsharex.com/) inspired cross platform utility written with
|Linux|Windows|OS X| |Linux|Windows|OS X|
|:---:|:-----:|:--:| |:---:|:-----:|:--:|
|[![Build Status](https://nativeci.arsenarsen.com/job/KShare/badge/icon)](https://nativeci.arsenarsen.com/job/KShare)| [![Build status](https://ci.appveyor.com/api/projects/status/7wa4f0bl6u62lo6v?svg=true)](https://ci.appveyor.com/project/ArsenArsen/kshare)| Soon | |[![Build Status](https://nativeci.arsenarsen.com/job/KShare/badge/icon)](https://nativeci.arsenarsen.com/job/KShare)| [![Build status](https://ci.appveyor.com/api/projects/status/7wa4f0bl6u62lo6v?svg=true)](https://ci.appveyor.com/project/ArsenArsen/kshare)| [![Build Status](https://travis-ci.org/ArsenArsen/KShare.svg?branch=master)](https://travis-ci.org/ArsenArsen/KShare) |
## Screenshot ## Screenshot
Made with KShare itself, of course :) Made with KShare itself, of course :)
![](http://i.imgur.com/ffWvCun.png) ![](http://i.imgur.com/ffWvCun.png)

View File

@ -23,6 +23,8 @@ CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) {
view->move(p.x() + settings::settings().value("cropx", 0).toInt(), p.y() + settings::settings().value("cropy", 0).toInt()); view->move(p.x() + settings::settings().value("cropx", 0).toInt(), p.y() + settings::settings().value("cropy", 0).toInt());
view->setWindowTitle("KShare Crop Editor"); view->setWindowTitle("KShare Crop Editor");
view->show(); view->show();
view->raise();
view->activateWindow();
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop); connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
} }

View File

@ -92,6 +92,10 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap)
initMagnifierGrid(); initMagnifierGrid();
updateMag(); updateMag();
addItem(hint);
hint->setPos(5, 5);
hint->setZValue(2);
hint->setVisible(settings::settings().value("crophint", true).toBool());
connect(menu.addAction("Set Font"), &QAction::triggered, this, &CropScene::fontAsk); connect(menu.addAction("Set Font"), &QAction::triggered, this, &CropScene::fontAsk);
QPolygonF poly; QPolygonF poly;
@ -169,6 +173,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
QCursor::setPos(views()[0]->mapToGlobal(cursorPos.toPoint())); QCursor::setPos(views()[0]->mapToGlobal(cursorPos.toPoint()));
} else } else
cursorPos = e->scenePos(); cursorPos = e->scenePos();
hint->setVisible(!hint->sceneBoundingRect().contains(cursorPos));
cursorItem->setPos(cursorPos); cursorItem->setPos(cursorPos);
updateMag(); updateMag();
@ -283,6 +288,11 @@ void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) {
void CropScene::keyReleaseEvent(QKeyEvent *event) { void CropScene::keyReleaseEvent(QKeyEvent *event) {
if (((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !drawingSelection) || event->key() == Qt::Key_Escape) if (((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !drawingSelection) || event->key() == Qt::Key_Escape)
done(event->key() != Qt::Key_Escape); done(event->key() != Qt::Key_Escape);
else if (event->key() == Qt::Key_F1) {
bool enabled = !settings::settings().value("crophint", true).toBool();
hint->setVisible(enabled);
settings::settings().setValue("crophint", enabled);
}
} }
void CropScene::updateMag() { void CropScene::updateMag() {
@ -338,6 +348,7 @@ void CropScene::initMagnifierGrid() {
void CropScene::done(bool notEsc) { void CropScene::done(bool notEsc) {
if (notEsc && rect) { if (notEsc && rect) {
hint->setVisible(false);
rect->setPen(QPen(Qt::NoPen)); rect->setPen(QPen(Qt::NoPen));
magnifier->setVisible(false); magnifier->setVisible(false);
cursorItem->setVisible(false); cursorItem->setVisible(false);

View File

@ -9,6 +9,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <functional> #include <functional>
#include <screenshotutil.hpp>
class CropScene; class CropScene;
#include <cropeditor/drawing/drawitem.hpp> #include <cropeditor/drawing/drawitem.hpp>
@ -79,6 +80,19 @@ private:
QList<QGraphicsRectItem *> gridRectsX; QList<QGraphicsRectItem *> gridRectsX;
QList<QGraphicsRectItem *> gridRectsY; QList<QGraphicsRectItem *> gridRectsY;
QGraphicsPolygonItem *cursorItem = nullptr; QGraphicsPolygonItem *cursorItem = nullptr;
QGraphicsPixmapItem *hint = new QGraphicsPixmapItem(screenshotutil::renderText( //
"Press F1 to toggle this hint\n"
"\tHold Shift to slow the cursor down\n"
"\tCtrl+Drag a drawing to move it around\n"
"\tAlt+Click a drawing to remove it\n"
"\tPress Return/Enter to finish\n"
"\tPress ESC to cancel\n"
"\tRight-click to get a drawing menu\n"
"\tNOTE: You must select 'Reset pen selection' before closing the editor\n"
"\tIf you do not it will not close.",
5,
QColor(0, 0, 0, 125),
Qt::white));
}; };
#endif // CROPSCENE_HPP #endif // CROPSCENE_HPP

View File

@ -7,7 +7,7 @@
class BlurItem : public DrawItem { class BlurItem : public DrawItem {
public: public:
QString name() { QString name() override {
return "Blur"; return "Blur";
} }
~BlurItem() { ~BlurItem() {

View File

@ -7,7 +7,7 @@ class EllipseItem : public DrawItem {
public: public:
EllipseItem() { EllipseItem() {
} }
QString name() { QString name() override {
return "Blur"; return "Blur";
} }
~EllipseItem() { ~EllipseItem() {

View File

@ -89,7 +89,7 @@ int main(int argc, char *argv[]) {
Worker::init(); Worker::init();
a.connect(&a, &QApplication::aboutToQuit, Worker::end); a.connect(&a, &QApplication::aboutToQuit, Worker::end);
a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; }); a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; });
screenshotutil::renderText("DICKS").save("/home/arsen/test.png");
if (!parser.isSet(h)) w.show(); if (!parser.isSet(h)) w.show();
return a.exec(); return a.exec();
} }

View File

@ -13,7 +13,7 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
@ -62,7 +62,7 @@
<item row="4" column="0"> <item row="4" column="0">
<widget class="QTabWidget" name="videoTabs"> <widget class="QTabWidget" name="videoTabs">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="hTab"> <widget class="QWidget" name="hTab">
<property name="layoutDirection"> <property name="layoutDirection">
@ -162,7 +162,7 @@
<attribute name="title"> <attribute name="title">
<string>VP9</string> <string>VP9</string>
</attribute> </attribute>
<layout class="QFormLayout" name="verticalLayout"> <layout class="QFormLayout" name="verticalLayout1">
<item row="0" column="1"> <item row="0" column="1">
<widget class="QCheckBox" name="vp9Lossless"> <widget class="QCheckBox" name="vp9Lossless">
<property name="text"> <property name="text">
@ -176,7 +176,7 @@
<attribute name="title"> <attribute name="title">
<string>GIF</string> <string>GIF</string>
</attribute> </attribute>
<layout class="QFormLayout" name="verticalLayout"> <layout class="QFormLayout" name="verticalLayout2">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">

View File

@ -22,19 +22,10 @@ RecordingFormats::RecordingFormats(formats::Recording f) {
validator = [](QSize) { return false; }; validator = [](QSize) { return false; };
return; return;
} }
tmpDir = QDir(tmp);
QString name
= QString("KShareTemp-") + QString::number(PlatformBackend::inst().pid()) + "-" + QTime::currentTime().toString();
tmpDir.mkdir(name);
tmpDir.cd(name);
iFormat = QImage::Format_RGB888; iFormat = QImage::Format_RGB888;
path = tmpDir.absoluteFilePath("res." + formats::recordingFormatName(f).toLower()); path = tmpDir.filePath("res." + formats::recordingFormatName(f).toLower());
finalizer = [&] { finalizer = [&] {
delete enc; delete enc;
if (interrupt || !frameAdded) {
tmpDir.removeRecursively();
return QString();
}
return QFile(path).size() > 0 ? path : QString(); return QFile(path).size() > 0 ? path : QString();
}; };
validator = [&](QSize s) { validator = [&](QSize s) {
@ -69,10 +60,7 @@ RecordingFormats::RecordingFormats(formats::Recording f) {
interrupt = true; interrupt = true;
} }
}; };
postUploadTask = [&] { postUploadTask = [&] { QScopedPointer<RecordingFormats> th(this); };
tmpDir.removeRecursively();
QScopedPointer<RecordingFormats> th(this);
};
anotherFormat = formats::recordingFormatName(f); anotherFormat = formats::recordingFormatName(f);
} }

View File

@ -5,6 +5,7 @@
#include <QFile> #include <QFile>
#include <QImage> #include <QImage>
#include <QString> #include <QString>
#include <QTemporaryDir>
#include <formats.hpp> #include <formats.hpp>
#include <functional> #include <functional>
@ -27,7 +28,7 @@ private:
std::function<void()> postUploadTask; std::function<void()> postUploadTask;
std::vector<QImage> frames; std::vector<QImage> frames;
QImage::Format iFormat; QImage::Format iFormat;
QDir tmpDir; QTemporaryDir tmpDir;
QString path; QString path;
Encoder *enc = NULL; Encoder *enc = NULL;
bool interrupt = false; bool interrupt = false;

View File

@ -35,7 +35,7 @@ ScreenAreaSelector::~ScreenAreaSelector() {
void ScreenAreaSelector::keyPressEvent(QKeyEvent *event) { void ScreenAreaSelector::keyPressEvent(QKeyEvent *event) {
event->accept(); event->accept();
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
QRect r = QRect(pos(), rect().size()); QRect r = QRect(mapToGlobal(pos()), rect().size());
emit selectedArea(r); emit selectedArea(r);
close(); close();
} else if (event->key() == Qt::Key_Escape) } else if (event->key() == Qt::Key_Escape)

View File

@ -75,5 +75,27 @@ QPoint screenshotutil::smallestScreenCoordinate() {
return smallestCoordinate; return smallestCoordinate;
} }
QPixmap screenshotutil::renderText(QString toRender, QColor background, QFont font) { QPixmap screenshotutil::renderText(QString toRender, int padding, QColor background, QColor pen, QFont font) {
QFontMetrics metric(font);
QStringList lines = toRender.replace("\r", "").split('\n');
QSize resultingSize(0, padding * 2);
int lineSpace = metric.leading();
for (QString line : lines) {
QRect br = metric.boundingRect(line);
resultingSize.rheight() += lineSpace + br.height();
resultingSize.rwidth() = qMax(br.width(), resultingSize.width());
}
resultingSize.rwidth() += padding * 2;
QPixmap renderred(resultingSize);
renderred.fill(background);
QPainter painter(&renderred);
painter.setPen(pen);
int y = padding;
for (QString line : lines) {
QRect br = metric.boundingRect(line);
painter.drawText(padding, y, br.width(), br.height(), 0, line);
y += lineSpace + br.height();
}
painter.end();
return renderred;
} }

View File

@ -10,7 +10,7 @@ QPixmap fullscreenArea(bool cursor = true, qreal x = 0, qreal y = 0, qreal w = -
QPixmap window(WId wid, QScreen *w = QApplication::primaryScreen()); QPixmap window(WId wid, QScreen *w = QApplication::primaryScreen());
void toClipboard(QString value); void toClipboard(QString value);
QPoint smallestScreenCoordinate(); QPoint smallestScreenCoordinate();
QPixmap renderText(QString toRender, QColor background = Qt::transparent, QFont font = QFont()); QPixmap renderText(QString toRender, int padding = 5, QColor background = Qt::transparent, QColor pen = Qt::white, QFont font = QFont());
} }
#endif // SCREENSHOTUTIL_HPP #endif // SCREENSHOTUTIL_HPP