diff options
Diffstat (limited to 'src-qt5/desktop-utils')
18 files changed, 155 insertions, 197 deletions
diff --git a/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp b/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp index 47c6bfe1..3d901e8c 100644 --- a/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp @@ -67,6 +67,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->actionUSB_Image->setEnabled(false); loadIcons(); ui->tree_contents->setHeaderLabels( QStringList() << tr("File") << tr("MimeType") << tr("Size")+" " ); + + preservePaths = false; } MainUI::~MainUI(){ @@ -296,7 +298,7 @@ void MainUI::simpleExtractFiles(){ void MainUI::autoArchiveFiles(){ qDebug() << "Auto Archive Files:" << aaFileList; ui->label_progress->setText(tr("Adding Items...")); - BACKEND->startAdd(aaFileList); + BACKEND->startAdd(aaFileList, true); } void MainUI::extractSelection(){ diff --git a/src-qt5/desktop-utils/lumina-archiver/MainUI.h b/src-qt5/desktop-utils/lumina-archiver/MainUI.h index 1a9d287c..0a5c094c 100644 --- a/src-qt5/desktop-utils/lumina-archiver/MainUI.h +++ b/src-qt5/desktop-utils/lumina-archiver/MainUI.h @@ -26,13 +26,14 @@ public: void LoadArguments(QStringList); void loadIcons(); + bool preservePaths; private: Ui::MainUI *ui; - Backend *BACKEND; - QStringList aaFileList, sxList; - QString sxPath, sxFile; - QTimer *delayClose; + Backend *BACKEND; + QStringList aaFileList, sxList; + QString sxPath, sxFile; + QTimer *delayClose; QTreeWidgetItem* findItem(QString path, QTreeWidgetItem *start = 0); bool cleanItems(QStringList list, QTreeWidgetItem *start = 0); //returns true if anything gets cleaned diff --git a/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp b/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp index 5338efec..91e233d0 100644 --- a/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp +++ b/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp @@ -91,7 +91,7 @@ QString Backend::linkTo(QString file){ } //Modification routines -void Backend::startAdd(QStringList paths){ +void Backend::startAdd(QStringList paths, bool absolutePaths){ //if(paths.isEmpty() && !insertQueue.isEmpty()){ paths = insertQueue; } //load the queue if(paths.contains(filepath)){ paths.removeAll(filepath); } if(paths.isEmpty()){ return; } @@ -109,11 +109,12 @@ void Backend::startAdd(QStringList paths){ args << "-c" << "-a"; args << flags; //Now setup the parent dir - for(int i=0; i<paths.length(); i++){ - paths[i] = paths[i].section(parent,1,-1); - if(paths[i].startsWith("/")){ paths[i].remove(0,1); } - } - args << "-C" << parent; + if(!absolutePaths) { + for(int i=0; i<paths.length(); i++){ + paths[i] = paths[i].section(parent,1,-1); + if(paths[i].startsWith("/")){ paths[i].remove(0,1); } + } + args << "-C" << parent; } args << paths; if(QFile::exists(filepath)){ //append to existing args.replaceInStrings(filepath, tmpfilepath); diff --git a/src-qt5/desktop-utils/lumina-archiver/TarBackend.h b/src-qt5/desktop-utils/lumina-archiver/TarBackend.h index 56a7dcfe..cb24a053 100644 --- a/src-qt5/desktop-utils/lumina-archiver/TarBackend.h +++ b/src-qt5/desktop-utils/lumina-archiver/TarBackend.h @@ -33,7 +33,7 @@ public: QString linkTo(QString file); //Modification routines - void startAdd(QStringList paths); + void startAdd(QStringList paths, bool absolutePaths = false); void startRemove(QStringList paths); void startExtract(QString path, bool overwrite, QString file=""); //path to dir, overwrite, optional file to extract (everything otherwise) void startExtract(QString path, bool overwrite, QStringList files); diff --git a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_da.ts b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_da.ts index 5cdf9fa4..7ae80a69 100644 --- a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_da.ts +++ b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_da.ts @@ -16,7 +16,7 @@ <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="610"/> <source>Education</source> - <translation>Uddannelse</translation> + <translation>Læring</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="611"/> @@ -41,7 +41,7 @@ <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="615"/> <source>Science</source> - <translation>Videnskab</translation> + <translation>Naturvidenskab</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="616"/> @@ -56,7 +56,7 @@ <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="618"/> <source>Utility</source> - <translation>Hjælpeværktøj</translation> + <translation>Redskab</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="619"/> diff --git a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_nl.ts b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_nl.ts index 9947da6d..1cba660b 100644 --- a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_nl.ts +++ b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_nl.ts @@ -6,67 +6,67 @@ <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="608"/> <source>Multimedia</source> - <translation type="unfinished"></translation> + <translation>Multimedia</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="609"/> <source>Development</source> - <translation type="unfinished"></translation> + <translation>Ontwikkeling</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="610"/> <source>Education</source> - <translation type="unfinished"></translation> + <translation>Onderwijs</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="611"/> <source>Games</source> - <translation type="unfinished"></translation> + <translation>Spellen</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="612"/> <source>Graphics</source> - <translation type="unfinished"></translation> + <translation>Grafisch</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="613"/> <source>Network</source> - <translation type="unfinished"></translation> + <translation>Netwerk</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="614"/> <source>Office</source> - <translation type="unfinished"></translation> + <translation>Kantoor</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="615"/> <source>Science</source> - <translation type="unfinished"></translation> + <translation>Wetenschappelijk</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="616"/> <source>Settings</source> - <translation type="unfinished"></translation> + <translation>Instellingen</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="617"/> <source>System</source> - <translation type="unfinished"></translation> + <translation>Systeem</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="618"/> <source>Utility</source> - <translation type="unfinished"></translation> + <translation>Hulpmiddel</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="619"/> <source>Wine</source> - <translation type="unfinished"></translation> + <translation>Wine</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="620"/> <source>Unsorted</source> - <translation type="unfinished"></translation> + <translation>Ongesorteerd</translation> </message> </context> <context> @@ -75,22 +75,22 @@ <location filename="../mainUI.ui" line="14"/> <location filename="../mainUI.cpp" line="53"/> <source>Calculator</source> - <translation type="unfinished"></translation> + <translation>Rekenmachine</translation> </message> <message> <location filename="../mainUI.ui" line="657"/> <source>Advanced Operations</source> - <translation type="unfinished"></translation> + <translation>Geavanceerde bewerkingen</translation> </message> <message> <location filename="../mainUI.cpp" line="83"/> <source>Percentage %1</source> - <translation type="unfinished"></translation> + <translation>Percentage %1</translation> </message> <message> <location filename="../mainUI.cpp" line="85"/> <source>Power %1</source> - <translation type="unfinished"></translation> + <translation>Prestatie %1</translation> </message> <message> <location filename="../mainUI.cpp" line="87"/> diff --git a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_pt_BR.ts b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_pt_BR.ts index 153a01b4..e26ecb58 100644 --- a/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_pt_BR.ts +++ b/src-qt5/desktop-utils/lumina-calculator/i18n/l-calc_pt_BR.ts @@ -6,67 +6,67 @@ <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="608"/> <source>Multimedia</source> - <translation type="unfinished"></translation> + <translation>Multimídia</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="609"/> <source>Development</source> - <translation type="unfinished"></translation> + <translation>Desenvolvimento</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="610"/> <source>Education</source> - <translation type="unfinished"></translation> + <translation>Educação</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="611"/> <source>Games</source> - <translation type="unfinished"></translation> + <translation>Jogos</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="612"/> <source>Graphics</source> - <translation type="unfinished"></translation> + <translation>Gráficos</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="613"/> <source>Network</source> - <translation type="unfinished"></translation> + <translation>Rede</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="614"/> <source>Office</source> - <translation type="unfinished"></translation> + <translation>Escritório</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="615"/> <source>Science</source> - <translation type="unfinished"></translation> + <translation>Ciência</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="616"/> <source>Settings</source> - <translation type="unfinished"></translation> + <translation>Configurações</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="617"/> <source>System</source> - <translation type="unfinished"></translation> + <translation>Sistema</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="618"/> <source>Utility</source> - <translation type="unfinished"></translation> + <translation>Utilitários</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="619"/> <source>Wine</source> - <translation type="unfinished"></translation> + <translation>Wine</translation> </message> <message> <location filename="../../../core/libLumina/LuminaXDG.cpp" line="620"/> <source>Unsorted</source> - <translation type="unfinished"></translation> + <translation>Não classificado</translation> </message> </context> <context> diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp index 7a25357a..be00e675 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp @@ -1,9 +1,8 @@ #include "PrintWidget.h" -PrintWidget::PrintWidget(QPrinter* printer, QWidget *parent) : QGraphicsView(parent), scene(0), curPage(1), +PrintWidget::PrintWidget(QWidget *parent) : QGraphicsView(parent), scene(0), curPage(1), viewMode(SinglePageView), zoomMode(FitInView), zoomFactor(1), initialized(false), fitting(true) { - this->printer = printer; this->setMouseTracking(true); QList<QWidget*> children = this->findChildren<QWidget*>("",Qt::FindChildrenRecursively); for(int i=0; i<children.length(); i++){ @@ -68,7 +67,7 @@ void PrintWidget::setViewMode(ViewMode mode) { this->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio); fitting = false; zoomMode = CustomZoom; - zoomFactor = this->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY()); + //zoomFactor = this->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY()); } else { fitting = true; fit(); @@ -121,23 +120,15 @@ void PrintWidget::setCurrentPage(int pageNumber) { } } +void PrintWidget::highlightText(int pageNum, QRectF textBox) { + PageItem *item = static_cast<PageItem*>(pages[pageNum]); + QPainter painter(this); + painter.fillRect(textBox, QColor(255, 255, 177, 128)); +} + //Private functions void PrintWidget::generatePreview() { - qDebug() << "generating preview"; - if(!previewEngine) - previewEngine = new QPreviewPaintEngine(); - if(!pdfEngine) - pdfEngine = new QPdfPrintEngine(QPrinter::HighResolution); - - printer->setEngines(previewEngine, previewEngine); - previewEngine->setProxyEngines(pdfEngine, pdfEngine); - - emit paintRequested(printer); - - printer->setEngines(pdfEngine, pdfEngine); - - qDebug() << "Populating Scene"; populateScene(); // i.e. setPreviewPrintedPictures() e.l. layoutPages(); curPage = qBound(1, curPage, pages.count()); @@ -153,13 +144,9 @@ void PrintWidget::layoutPages() { int numPagePlaces = numPages; int cols = 1; // singleMode and default if (viewMode == AllPagesView) { - if (printer->orientation() == QPrinter::Portrait) - cols = qCeil(qSqrt(numPages)); - else - cols = qFloor(qSqrt(numPages)); + cols = ((pictures->value(0)).width() > (pictures->value(0)).height()) ? qFloor(qSqrt(numPages)) : qCeil(qSqrt(numPages)); cols += cols % 2; // Nicer with an even number of cols - } - else if (viewMode == FacingPagesView) { + } else if (viewMode == FacingPagesView) { cols = 2; numPagePlaces += 1; } @@ -186,21 +173,19 @@ void PrintWidget::populateScene() scene->removeItem(pages.at(i)); qDeleteAll(pages); pages.clear(); - qDebug() << "Pages cleared"; int numPages = pictures->count(); - QSize paperSize = printer->pageLayout().fullRectPixels(printer->resolution()).size(); - QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution()); - qDebug() << "Fields set"; + //Replace from loadingHash resolution + QSize paperSize = pictures->value(0).size(); + qDebug() << "Image paperSize" << paperSize; for (int i = 0; i < numPages; i++) { - PageItem* item = new PageItem(i+1, (*pictures)[i], paperSize, pageRect); + PageItem* item = new PageItem(i+1, (*pictures)[i], paperSize); scene->addItem(item); pages.append(item); } } - //Private Slots void PrintWidget::updateCurrentPage() { if (viewMode == AllPagesView) @@ -282,9 +267,13 @@ void PrintWidget::fit(bool doFitting) { } } - zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY()); + //zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY()); } void PrintWidget::setPictures(QHash<int, QImage> *hash) { pictures = hash; } + +void PrintWidget::setOrientation(QPageLayout::Orientation ori) { + this->orientation = ori; +} diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h index 81e4e794..62543e45 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h @@ -18,18 +18,18 @@ #include <QScrollBar> #include <QStyleOptionGraphicsItem> #include <QtMath> -#include <QPrinter> +#include <QPageLayout> + namespace { class PageItem : public QGraphicsItem { public: - PageItem(int _pageNum, const QImage _pagePicture, QSize _paperSize, QRect _pageRect) + PageItem(int _pageNum, const QImage _pagePicture, QSize _paperSize) : pageNum(_pageNum), pagePicture(_pagePicture), - paperSize(_paperSize), pageRect(_pageRect) + paperSize(_paperSize) { - qreal border = qMax(paperSize.height(), paperSize.width()) / 25; - brect = QRectF(QPointF(-border, -border), - QSizeF(paperSize)+QSizeF(2*border, 2*border)); + brect = QRectF(QPointF(-25, -25), + QSizeF(paperSize)+QSizeF(50, 50)); setCacheMode(DeviceCoordinateCache); } @@ -45,7 +45,6 @@ private: int pageNum; const QImage pagePicture; QSize paperSize; - QRect pageRect; QRectF brect; }; @@ -78,17 +77,11 @@ void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->setClipRect(paperRect & option->exposedRect); painter->fillRect(paperRect, Qt::white); - if (pagePicture.isNull()) - return; - painter->drawImage(pageRect.topLeft(), pagePicture); - - // Effect: make anything drawn in the margins look washed out. - QPainterPath path; - path.addRect(paperRect); - path.addRect(pageRect); - painter->setPen(QPen(Qt::NoPen)); - painter->setBrush(QColor(255, 255, 255, 180)); - painter->drawPath(path); + if (pagePicture.isNull()){ + qDebug() << "NULL"; + return; + } + painter->drawImage(QPoint(0,0), pagePicture); } } @@ -96,7 +89,7 @@ class PrintWidget : public QGraphicsView { Q_OBJECT public: - PrintWidget(QPrinter *printer, QWidget *parent = 0); + PrintWidget(QWidget *parent = 0); ~PrintWidget(); enum ViewMode { SinglePageView, @@ -118,23 +111,25 @@ public: signals: void resized(); void customContextMenuRequested(const QPoint&); - void paintRequested(QPrinter*); public slots: void zoomIn(double factor=1.2); void zoomOut(double factor=1.2); void setCurrentPage(int); void setVisible(bool) Q_DECL_OVERRIDE; + void setOrientation(QPageLayout::Orientation); + void highlightText(int, QRectF); + void updatePreview(); void fitView(); void fitToWidth(); void setAllPagesViewMode(); void setSinglePageViewMode(); void setFacingPagesViewMode(); +private slots: void updateCurrentPage(); int calcCurrentPage(); void fit(bool doFitting=false); - void updatePreview(); protected: void resizeEvent(QResizeEvent* e) Q_DECL_OVERRIDE { /*{ @@ -156,16 +151,14 @@ private: void setViewMode(ViewMode); void setZoomMode(ZoomMode); QGraphicsScene *scene; - QPrinter *printer; - QPreviewPaintEngine *previewEngine; - QPdfPrintEngine *pdfEngine; int curPage; ViewMode viewMode; ZoomMode zoomMode; + QPageLayout::Orientation orientation; double zoomFactor; bool initialized, fitting; - QList<QGraphicsItem *> pages; + QList<QGraphicsItem*> pages; QHash<int, QImage> *pictures; }; #endif diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index 4e65a766..57afbfe1 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -27,13 +27,13 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ ui->setupUi(this); this->setWindowTitle(tr("Lumina PDF Viewer")); this->setWindowIcon( LXDG::findIcon("application-pdf","unknown")); - this->highlight = false; presentationLabel = 0; CurrentPage = 1; lastdir = QDir::homePath(); - Printer = new QPrinter(); //Create the interface widgets - WIDGET = new PrintWidget(Printer, this); + WIDGET = new PrintWidget(this); + WIDGET->setVisible(false); + WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); clockTimer = new QTimer(this); clockTimer->setInterval(1000); //1-second updates to clock connect(clockTimer, SIGNAL(timeout()), this, SLOT(updateClock()) ); @@ -52,13 +52,11 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ this->setCentralWidget(WIDGET); WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); connect(WIDGET, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(showContextMenu(const QPoint&)) ); - connect(WIDGET, &PrintWidget::paintRequested, this, - [=](QPrinter *printer) { this->paintOnWidget(printer, this->highlight); }); DOC = 0; connect(this, SIGNAL(PageLoaded(int)), this, SLOT(slotPageLoaded(int)) ); PrintDLG = new QPrintDialog(this); - //connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintToPrinter(QPrinter*)) ); + connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintToPrinter(QPrinter*)) ); //connect(ui->menuStart_Presentation, SIGNAL(triggered(QAction*)), this, SLOT(slotStartPresentation(QAction*)) ); //Create the other interface widgets @@ -231,17 +229,15 @@ void MainUI::loadFile(QString path){ Poppler::Page *PAGE = DOC->page(0); if(PAGE!=0){ lastdir = path.section("/",0,-2); //save this for later - Printer->setPageSize( QPageSize(PAGE->pageSize(), QPageSize::Point) ); - Printer->setPageMargins(QMarginsF(0,0,0,0), QPageLayout::Point); switch(PAGE->orientation()){ case Poppler::Page::Landscape: - Printer->setOrientation(QPrinter::Landscape); break; + WIDGET->setOrientation(QPageLayout::Landscape); break; default: - Printer->setOrientation(QPrinter::Portrait); + WIDGET->setOrientation(QPageLayout::Portrait); } delete PAGE; qDebug() << " - Document Setup : start loading pages now"; - startLoadingPages(Printer); + startLoadingPages(); //QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //start loading the file preview } @@ -253,7 +249,7 @@ void MainUI::loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, Q // Using Qt to scale the image (adjust page value) smooths out the image quite a bit without a lot of performance loss (but cannot scale up without pixelization) // The best approach seams to be to increase the DPI a bit, but match that with the same scaling on the page size (smoothing) - qDebug() << " - Render Page:" << num; + //qDebug() << " - Render Page:" << num; Poppler::Page *PAGE = doc->page(num); if(PAGE!=0){ //qDebug() << "DPI:" << dpi << "Size:" << page << "Page Size (pt):" << PAGE->pageSize(); @@ -263,7 +259,6 @@ void MainUI::loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, Q //qDebug() << " - Raw Image Size:" << raw.size(); loadingHash.insert(num, raw.scaled(scalefactor*page.width(), scalefactor*page.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) ); raw = QImage(); //clear it - //qDebug() << "Page Label:" << num << PAGE->label(); /* QList<Annotation*> anno = PAGE->annotations(Annotations::AText ); QStringList annoS; @@ -382,7 +377,7 @@ void MainUI::endPresentation(){ this->releaseKeyboard(); } -void MainUI::startLoadingPages(QPrinter *printer){ +void MainUI::startLoadingPages(){ if(numPages>0){ return; } //currently loaded[ing] qDebug() << " - Start Loading Pages"; numPages = DOC->numPages(); @@ -390,17 +385,18 @@ void MainUI::startLoadingPages(QPrinter *printer){ progress->setRange(0,numPages); progress->setValue(0); progAct->setVisible(true); - QRectF pageSize = printer->pageRect(QPrinter::DevicePixel); - QSize DPI(printer->resolution(),printer->resolution()); + QSizeF pageSize = DOC->page(0)->pageSizeF()*2; + //QSize DPI(loadingHash[0]->resolution(),loadingHash[0]->resolution()); + QSize DPI(76,76); /*qDebug() << "Screen Resolutions:"; QList<QScreen*> screens = QApplication::screens(); for(int i=0; i<screens.length(); i++){ qDebug() << screens[i]->name() << screens[i]->logicalDotsPerInchX() << screens[i]->logicalDotsPerInchY(); }*/ + qDebug() << "Poppler pageSize: " << pageSize; for(int i=0; i<numPages; i++){ - qDebug() << " - Kickoff page load:" << i; - //this->ccw = 0; - QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, DPI, pageSize.size()); + //qDebug() << " - Kickoff page load:" << i; + QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, DPI, pageSize); } } @@ -412,7 +408,8 @@ void MainUI::slotPageLoaded(int page){ progAct->setVisible(false); qDebug() << "Setting Pictures"; WIDGET->setPictures(&loadingHash); - QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); + WIDGET->setVisible(true); + //QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //qDebug() << "Updating"; ui->actionStop_Presentation->setEnabled(false); ui->actionStart_Here->setEnabled(true); @@ -426,52 +423,6 @@ void MainUI::slotPageLoaded(int page){ startPresentation(act == ui->actionAt_Beginning); }*/ -void MainUI::paintOnWidget(QPrinter *PRINTER, bool highlight){ - static bool first = true; - static bool shrunk = false; - if(DOC==0){ return; } - if(loadingHash.keys().length() != numPages){ startLoadingPages(PRINTER); return; } - //Increase the resolution of the page to match the image to prevent downscaling - if(first) - PRINTER->setPageSize(QPageSize(PRINTER->pageRect().size()*2)); - qDebug() << PRINTER->pageRect().size() << loadingHash[0].size() << WIDGET->size(); - QPainter painter(PRINTER); - painter.setPen(Qt::NoPen); - if(ui->findGroup->isVisible()) { - QSize size = PRINTER->pageRect().size(); - size = QSize(size.width(), size.height()-ui->findGroup->height()); - PRINTER->setPageSize(QPageSize(size)); - shrunk = true; - }else if(shrunk){ - QSize size = PRINTER->pageRect().size(); - size = QSize(size.width(), size.height()+ui->findGroup->height()); - PRINTER->setPageSize(QPageSize(size)); - shrunk = false; - } - if(highlight) { - Poppler::TextBox *currentText = results.keys()[currentHighlight]; - int pageNum = results.value(currentText), i; - - for(i = 0; i <= pageNum; i++) - if(i != 0){ PRINTER->newPage(); } - - qDebug() << pageNum << i; - this->highlight=false; - }else { - for(int i=0; i<numPages; i++){ - if(i != 0){ PRINTER->newPage(); } //this is the start of the next page (not needed for first) - if(loadingHash.contains(i)){ - painter.drawImage(0,0, loadingHash[i].scaled(PRINTER->pageRect().size(), - Qt::KeepAspectRatio, Qt::SmoothTransformation)); - } - else{ painter.drawImage(0,0, QImage()); } - } - WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); - //loadingHash.clear(); - first = false; - } -} - void MainUI::paintToPrinter(QPrinter *PRINTER){ if(loadingHash.keys().length() != numPages){ return; } @@ -561,9 +512,8 @@ void MainUI::rotate(bool ccw) { loadingHash.insert(i, image); } //Rotates the page as well as the image - Printer->setOrientation((Printer->orientation() == QPrinter::Landscape) ? - QPrinter::Portrait : QPrinter::Landscape); - + //WIDGET->setOrientation((WIDGET->orientation() == QPageLayout::Landscape) ? + //QPageLayout::Portrait : QPageLayout::Landscape); QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); } @@ -664,9 +614,9 @@ void MainUI::find(QString text, bool forward) { Poppler::TextBox *currentText = results.keys()[currentHighlight]; WIDGET->setCurrentPage(results.value(currentText)); + WIDGET->highlightText(currentHighlight, currentText->boundingBox()); - QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); - this->highlight = true; + QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); }else{ //Print "No results found" } @@ -705,16 +655,3 @@ void MainUI::resizeEvent(QResizeEvent *event) { } QMainWindow::resizeEvent(event); } - -void MainUI::highlightText(QPrinter *PRINTER) { - Poppler::TextBox *currentText = results.keys()[currentHighlight]; - QPainter painter(PRINTER); - painter.setPen(Qt::NoPen); - int pageNum = results.value(currentText), i; - - for(i = 0; i <= pageNum; i++) - if(i != 0){ PRINTER->newPage(); } - - qDebug() << pageNum << i; - this->highlight=false; -} diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index b3ad38f1..2d23b402 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -41,10 +41,9 @@ private: PrintWidget *WIDGET; Ui::MainUI *ui; PropDialog *PROPDIALOG; - QPrinter* Printer; QPrintDialog *PrintDLG; QString lastdir; - bool matchCase, highlight; + bool matchCase; QMap<Poppler::TextBox*, int> results; int currentHighlight; @@ -62,7 +61,6 @@ private: int numPages; void loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, QSizeF page); - void highlightText(QPrinter *PRINTER); //Functions/variables for the presentation mode PresentationLabel *presentationLabel; @@ -73,7 +71,7 @@ private: void endPresentation(); private slots: - void startLoadingPages(QPrinter *printer); + void startLoadingPages(); void slotPageLoaded(int); //void slotStartPresentation(QAction *act); @@ -85,12 +83,12 @@ private slots: void startPresentationHere(){ startPresentation(false); } void startPresentationBeginning(){ startPresentation(true); } void closePresentation(){ endPresentation(); } + void showInformation(); void find(QString text, bool forward); void enableFind(); void showBookmarks(); - void paintOnWidget(QPrinter*, bool); void paintToPrinter(QPrinter *PRINTER); //Button Slots diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp index 8626b2b4..b1592cc3 100644 --- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp @@ -76,17 +76,22 @@ void PlainTextEditor::LoadFile(QString filepath){ bool diffFile = (filepath != this->whatsThis()); this->setWhatsThis(filepath); this->clear(); - QList<SyntaxFile> files = SyntaxFile::availableFiles(settings); + /*QList<SyntaxFile> files = SyntaxFile::availableFiles(settings); for(int i=0; i<files.length(); i++){ if(files[i].supportsFile(filepath) ){ files[i].SetupDocument(this); SYNTAX->loadRules(files[i]); break; } - } + }*/ //SYNTAX->loadRules( Custom_Syntax::ruleForFile(filepath.section("/",-1), settings) ); lastSaveContents = LUtils::readFile(filepath).join("\n"); if(diffFile){ + SYNTAX->loadRules( Custom_Syntax::ruleForFile(this->whatsThis().section("/",-1), settings) ); + if(SYNTAX->loadedRules().isEmpty()){ + SYNTAX->loadRules( Custom_Syntax::ruleForFirstLine( lastSaveContents.section("\n",0,0,QString::SectionSkipEmpty) , settings) ); + } + SYNTAX->setupDocument(this); this->setPlainText( lastSaveContents ); }else{ //Try to keep the mouse cursor/scroll in the same position @@ -123,14 +128,18 @@ bool PlainTextEditor::SaveFile(bool newname){ if(file.isEmpty()){ return false; } //cancelled this->setWhatsThis(file); SYNTAX->loadRules( Custom_Syntax::ruleForFile(this->whatsThis().section("/",-1), settings) ); + if(SYNTAX->loadedRules().isEmpty()){ + SYNTAX->loadRules( Custom_Syntax::ruleForFirstLine( this->toPlainText().section("\n",0,0,QString::SectionSkipEmpty) , settings) ); + } + SYNTAX->setupDocument(this); SYNTAX->rehighlight(); - readonly = !QFileInfo(this->whatsThis()).isWritable(); //update this flag } if( !watcher->files().isEmpty() ){ watcher->removePaths(watcher->files()); } bool ok = LUtils::writeFile(this->whatsThis(), this->toPlainText().split("\n"), true); hasChanges = !ok; if(ok){ lastSaveContents = this->toPlainText(); emit FileLoaded(this->whatsThis()); } watcher->addPath(currentFile()); + readonly = !QFileInfo(this->whatsThis()).isWritable(); //update this flag return true; //qDebug() << " - Success:" << ok << hasChanges; } diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp index 53f51f4e..a80d4149 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp @@ -83,6 +83,16 @@ bool SyntaxFile::supportsFile(QString file){ return false; } +bool SyntaxFile::supportsFirstLine(QString line){ + line = line.simplified(); + if(metaObj.contains("first_line_match")){ + return metaObj.value("first_line_match").toArray().contains(line); + }else if(metaObj.contains("first_line_regex")){ + return (QRegExp( metaObj.value("first_line_regex").toString() ).indexIn(line) >=0 ); + } + return false; +} + bool SyntaxFile::LoadFile(QString file, QSettings *settings){ QStringList contents = LUtils::readFile(file); //Now trim the extra non-JSON off the beginning of the file @@ -209,6 +219,13 @@ QString Custom_Syntax::ruleForFile(QString filename, QSettings *settings){ return ""; } +QString Custom_Syntax::ruleForFirstLine(QString line, QSettings *settings){ + QList<SyntaxFile> files = SyntaxFile::availableFiles(settings); + for(int i=0; i<files.length(); i++){ + if(files[i].supportsFirstLine(line)){ return files[i].name(); } + } + return ""; +} void Custom_Syntax::loadRules(QString type){ QList<SyntaxFile> files = SyntaxFile::availableFiles(settings); diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h index bffbfd1a..9949a90c 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h @@ -46,6 +46,7 @@ public: void SetupDocument(QPlainTextEdit *editor); bool supportsFile(QString file); //does this syntax set support the file? + bool supportsFirstLine(QString line); //is the type of file defined by the first line of the file? ("#!/bin/<something>" for instance) //Main Loading routine (run this before other functions) bool LoadFile(QString file, QSettings *settings); @@ -66,10 +67,13 @@ public: } ~Custom_Syntax(){} + QString loadedRules(){ return syntax.name(); } + static QStringList availableRules(QSettings *settings); static QStringList knownColors(); static void SetupDefaultColors(QSettings *settings); static QString ruleForFile(QString filename, QSettings *settings); + static QString ruleForFirstLine(QString line, QSettings *settings); void loadRules(QString type); void loadRules(SyntaxFile sfile); @@ -77,6 +81,8 @@ public: loadRules( syntax.name() ); } + void setupDocument(QPlainTextEdit *edit){ syntax.SetupDocument(edit); } //simple redirect for the function in the currently-loaded rules + protected: void highlightBlock(const QString &text){ //qDebug() << "Highlight Block:" << text; @@ -159,7 +165,7 @@ protected: int last = text.length()-1; while(last>=0 && (text[last]==' ' || text[last]=='\t' ) ){ last--; } if(last < text.length()-1){ - setFormat(last+1, text.length()-1-last, fmt); + setFormat(last+1, text.length()-1-last, fmt); } } } diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md index fa00b557..04190672 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md @@ -9,9 +9,11 @@ A small comment section may be placed at the top of the file where every line st # Requirements 1. A "meta" object containing the following variables (meta information about the rules): 1. "name" : The name that will be shown to the user for this set of syntax rules. - 2. If this syntax file is to be automatically applied to particular file type, then one of the following options must be set: + 2. If this syntax file is to be automatically applied to particular file type, then at least one of the following options must be set: 1. "file_suffix" : An array of file extensions which are supported by this syntax rule set (Example: temp.foo will be matched by "file_suffix"=["foo"] ) 2. "file_regex" : A regular expression which should be used to find if the filename matches this rule set. + 3. "first_line_match" : *(only used if no filename rules matched)* Exact match for the first line of text in the file (Example: "#!/bin/sh") + 4. "first_line_regex" : *(only used if no filename rules matched)* Regular expression to use when find a match for the first line of text in the file 2. A "format" object containing the following variables (file-wide formatting): 1. "columns_per_line" : (integer, optional) For file formats with line-length restrictions, this will automatically highlight/flag any "overage" of the designated limit. 2. "highlight_whitespace_eol" : (boolian, optional) Highlight any excess whitespace at the end of a line. diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax index ab67d384..1982e599 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax @@ -8,7 +8,8 @@ { "meta": { "name": "JSON", - "file_suffix": ["json", "syntax"] + "file_suffix": ["json", "syntax"], + "first_line_match":["{"] }, "format": { "line_wrap": false, diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax index 6690d98c..2145beec 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax @@ -8,7 +8,8 @@ { "meta": { "name": "Python", - "file_suffix": ["py", "pyc"] + "file_suffix": ["py", "pyc"], + "first_line_regex" : "(#!).+(python)" }, "format": { "line_wrap": false, diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax index 5f38cadc..f2256731 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax @@ -8,7 +8,8 @@ { "meta": { "name": "Shell", - "file_suffix": ["sh"] + "file_suffix": ["sh"], + "first_line_match":["#!/bin/sh", "#!/sbin/openrc-run"] }, "format": { "line_wrap": false, |