Add support for saving result as SVG.

parent 30c12371
......@@ -49,7 +49,7 @@ include(KDECMakeSettings)
include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
include(ECMQtDeclareLoggingCategory)
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core Widgets)
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core Widgets Svg)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED
XmlGui # For app
KIO # For part
......
......@@ -58,6 +58,7 @@ target_link_libraries(filelight
KF5::I18n
KF5::XmlGui
KF5::KIOWidgets # Only used for KDirLister, may be able to move away from that.
Qt5::Svg
)
if (WIN32)
find_package(KDEWin REQUIRED)
......
......@@ -140,6 +140,7 @@ void MainWindow::setupActions() //singleton function
m_combo->setDuplicatesEnabled(false);
KStandardAction::open(this, SLOT(slotScanFolder()), ac);
KStandardAction::save(this, SLOT(slotSaveSvg()), ac)->setEnabled(false);
KStandardAction::quit(this, SLOT(close()), ac);
KStandardAction::up(this, SLOT(slotUp()), ac);
KStandardAction::configureToolbars(this, SLOT(configToolbars()), ac);
......@@ -229,6 +230,16 @@ void MainWindow::slotScanHomeFolder()
slotScanPath(QDir::homePath());
}
void MainWindow::slotSaveSvg()
{
QString path = QFileDialog::getSaveFileName(this, i18n("Save to SVG"));
if (path.isEmpty()) {
return;
}
m_map->saveSvg(path);
}
void MainWindow::slotScanRootFolder()
{
slotScanPath(QDir::rootPath());
......@@ -297,6 +308,8 @@ void MainWindow::scanCompleted()
stateChanged(QStringLiteral("scan_complete"));
action("file_save")->setEnabled(true);
m_combo->lineEdit()->setText(prettyUrl());
if (url.toLocalFile() == QLatin1String("/")) {
......
......@@ -66,6 +66,7 @@ private Q_SLOTS:
void slotComboScan();
void slotScanFolder();
void slotScanHomeFolder();
void slotSaveSvg();
void slotScanRootFolder();
bool slotScanUrl(const QUrl&);
bool slotScanPath(const QString&);
......
......@@ -25,6 +25,7 @@
#include <QFontMetrics> //ctor
#include <QPainter>
#include <QBrush>
#include <QSvgGenerator>
#include "filelight_debug.h"
#include <KCursor> //make()
......@@ -69,6 +70,13 @@ void RadialMap::Map::invalidate()
m_visibleDepth = Config::defaultRingDepth;
}
void RadialMap::Map::saveSvg(const QString &path)
{
QSvgGenerator svgGenerator;
svgGenerator.setFileName(path);
paint(&svgGenerator);
}
void RadialMap::Map::make(const Folder *tree, bool refresh)
{
//slow operation so set the wait cursor
......@@ -356,7 +364,7 @@ void RadialMap::Map::colorise()
}
}
void RadialMap::Map::paint(bool antialias)
void RadialMap::Map::paint(QPaintDevice *paintDevice)
{
KColorScheme scheme(QPalette::Active, KColorScheme::View);
......@@ -364,7 +372,14 @@ void RadialMap::Map::paint(bool antialias)
QRectF rect = m_rect;
rect.adjust(MAP_HIDDEN_TRIANGLE_SIZE, MAP_HIDDEN_TRIANGLE_SIZE, -MAP_HIDDEN_TRIANGLE_SIZE, -MAP_HIDDEN_TRIANGLE_SIZE);
m_pixmap.fill(Qt::transparent);
if (!paintDevice) {
if (m_pixmap.isNull()) {
return;
}
m_pixmap.fill(Qt::transparent);
paintDevice = &m_pixmap;
}
//m_rect.moveRight(1); // Uncommenting this breaks repainting when recreating map from cache
......@@ -372,15 +387,12 @@ void RadialMap::Map::paint(bool antialias)
//**** best option you can think of is to make the circles slightly less perfect,
// ** i.e. slightly eliptic when resizing inbetween
if (m_pixmap.isNull())
return;
if (!paint.begin(&m_pixmap)) {
qCWarning(FILELIGHT_LOG) << "Filelight::RadialMap Failed to initialize painting, returning...";
if (!paint.begin(paintDevice)) {
qWarning() << "Filelight::RadialMap Failed to initialize painting, returning...";
return;
}
if (antialias && Config::antialias) {
if (Config::antialias) {
paint.translate(0.7, 0.7);
paint.setRenderHint(QPainter::Antialiasing);
}
......@@ -394,6 +406,11 @@ void RadialMap::Map::paint(bool antialias)
++step;
}
if (m_signature.isEmpty()) {
qWarning() << "Map not created yet";
return;
}
for (int x = m_visibleDepth; x >= 0; --x) {
int width = rect.width() / 2;
......
......@@ -57,11 +57,13 @@ public:
return m_pixmap;
}
void saveSvg(const QString &path);
friend class Widget;
private:
void paint(bool antialias = true);
void paint(QPaintDevice *paintDevice = nullptr);
void colorise();
void setRingBreadth();
void findVisibleDepth(const Folder *dir, uint currentDepth = 0);
......
......@@ -174,7 +174,7 @@ RadialMap::Widget::refresh(int filth)
break;
case 2:
m_map.paint(true); //antialiased painting
m_map.paint();
break;
case 3:
......
......@@ -66,6 +66,8 @@ public:
friend class Label; //FIXME badness
void saveSvg(const QString &path) { m_map.saveSvg(path); }
public Q_SLOTS:
void zoomIn();
void zoomOut();
......
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