new style for the progressbars, display more info
authorLukas Hrazky <lukkash@email.cz>
Sat, 21 Aug 2010 11:47:51 +0000 (13:47 +0200)
committerLukas Hrazky <lukkash@email.cz>
Sat, 21 Aug 2010 21:22:39 +0000 (23:22 +0200)
Signed-off-by: Lukas Hrazky <lukkash@email.cz>

14 files changed:
case.pro
pixmaps/default/copy_small.xpm [new file with mode: 0644]
pixmaps/default/delete_small.xpm [new file with mode: 0644]
pixmaps/default/move_small.xpm [new file with mode: 0644]
src/button.cpp
src/fileoperator.cpp
src/fileoperator.h
src/main.cpp
src/progressbar.cpp
src/progressbar.h
src/style.cpp [new file with mode: 0644]
src/style.h [new file with mode: 0644]
src/utils.cpp [new file with mode: 0644]
src/utils.h [new file with mode: 0644]

index 95431d3..fe18116 100644 (file)
--- a/case.pro
+++ b/case.pro
@@ -22,7 +22,9 @@ HEADERS += src/addressbar.h \
            src/fileoperator.h \
            src/pane.h \
            src/dialog.h \
-           src/progressbar.h
+           src/progressbar.h \
+           src/style.h \
+           src/utils.h
 SOURCES += src/addressbar.cpp \
            src/button.cpp \
            src/case.cpp \
@@ -31,4 +33,6 @@ SOURCES += src/addressbar.cpp \
            src/main.cpp \
            src/pane.cpp \
            src/dialog.cpp \
-           src/progressbar.cpp
+           src/progressbar.cpp \
+           src/style.cpp \
+           src/utils.cpp
diff --git a/pixmaps/default/copy_small.xpm b/pixmaps/default/copy_small.xpm
new file mode 100644 (file)
index 0000000..d138022
--- /dev/null
@@ -0,0 +1,26 @@
+/* XPM */
+static char * copy_small_xpm[] = {
+"20 20 3 1",
+"      c None",
+".     c #0000FF",
+"+     c #FFFFFF",
+"                    ",
+"        +++         ",
+"        +.+         ",
+"        +.+         ",
+"     ++++.++++      ",
+"     +.......+      ",
+"     ++++.++++      ",
+"        +.+         ",
+"        +.+         ",
+"        +++  ++     ",
+"             +.+    ",
+"             +..+   ",
+"++++++++++++++...+  ",
+"+.................+ ",
+"+..................+",
+"+.................+ ",
+"++++++++++++++...+  ",
+"             +..+   ",
+"             +.+    ",
+"             ++     "};
diff --git a/pixmaps/default/delete_small.xpm b/pixmaps/default/delete_small.xpm
new file mode 100644 (file)
index 0000000..0971ed8
--- /dev/null
@@ -0,0 +1,26 @@
+/* XPM */
+static char * delete_small_xpm[] = {
+"20 20 3 1",
+"      c None",
+".     c #0000FF",
+"+     c #FFFFFF",
+"                    ",
+"    +          +    ",
+"   +.+        +.+   ",
+"  +...+      +...+  ",
+" +.....+    +.....+ ",
+"  +.....+  +.....+  ",
+"   +.....++.....+   ",
+"    +..........+    ",
+"     +........+     ",
+"      +......+      ",
+"      +......+      ",
+"     +........+     ",
+"    +..........+    ",
+"   +.....++.....+   ",
+"  +.....+  +.....+  ",
+" +.....+    +.....+ ",
+"  +...+      +...+  ",
+"   +.+        +.+   ",
+"    +          +    ",
+"                    "};
diff --git a/pixmaps/default/move_small.xpm b/pixmaps/default/move_small.xpm
new file mode 100644 (file)
index 0000000..3092e0c
--- /dev/null
@@ -0,0 +1,26 @@
+/* XPM */
+static char * move_small_xpm[] = {
+"20 20 3 1",
+"      c None",
+".     c #0000FF",
+"+     c #FFFFFF",
+"                    ",
+"                    ",
+"                    ",
+"                    ",
+"                    ",
+"                    ",
+"                    ",
+"             ++     ",
+"             +.+    ",
+"             +..+   ",
+"++++++++++++++...+  ",
+"+.................+ ",
+"+..................+",
+"+.................+ ",
+"++++++++++++++...+  ",
+"             +..+   ",
+"             +.+    ",
+"             ++     ",
+"                    ",
+"                    "};
index d883c84..0f61a21 100644 (file)
@@ -19,8 +19,7 @@
 
 #include <iostream>
 
-#define ICON_PATH QString("/usr/share/pixmaps/case/")
-#define ICON_SET "default"
+#include "utils.h"
 
 
 Button::Button(const QString &name, QWidget *parent, const int maxWidth, const int maxHeight) :
@@ -30,23 +29,7 @@ Button::Button(const QString &name, QWidget *parent, const int maxWidth, const i
     setMaximumWidth(maxWidth);
     setMaximumHeight(maxHeight);
 
-    QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM");
-    if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG");
-    if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF");
-
-    iconImage = iconImage.convertToFormat(QImage::Format_Indexed8);
-
-    QRgb buttonText = palette().color(QPalette::ButtonText).rgb();
-    QRgb highlight = palette().color(QPalette::Highlight).rgb();
-    QVector<QRgb> colorTable = iconImage.colorTable();
-    for (QVector<QRgb>::iterator it = colorTable.begin(); it != colorTable.end(); ++it) {
-        if ((*it & 0xFFFFFF) == 0xFFFFFF) *it = (*it & 0xFF000000) | buttonText;
-        else if ((*it & 0xFFFFFF) == 0x0000FF) *it = (*it & 0xFF000000) | highlight;
-    }
-    iconImage.setColorTable(colorTable);
-
-    icons[0] = QIcon(QPixmap::fromImage(iconImage));
-    icons[1] = QIcon(QPixmap::fromImage(iconImage.mirrored(true, false)));
+    loadMiddleButtonIcons(palette(), name, icons[0], icons[1]);
 
     setIcon(icons[0]);
 }
index 422f90b..bd4c667 100644 (file)
@@ -24,6 +24,7 @@
 #include <QChar>
 
 #include "dialog.h"
+#include "utils.h"
 
 #include <math.h>
 #include <errno.h>
 FileOperator::FileOperator(QWidget *parent) : QWidget(parent) {
     QHBoxLayout *layout = new QHBoxLayout;
     layout->setContentsMargins(0, 0, 0, 0);
-    layout->setSpacing(0);
+    layout->setSpacing(1);
     setLayout(layout);
     qRegisterMetaType<QFileInfo>("QFileInfo");
+    loadOperationIcons(palette(), "delete_small", deleteIcon, inverseDeleteIcon);
+    loadOperationIcons(palette(), "copy_small", copyIcon, inverseCopyIcon);
+    loadOperationIcons(palette(), "move_small", moveIcon, inverseMoveIcon);
 }
 
 
@@ -167,7 +171,9 @@ void FileOperator::deleteFiles(const QFileInfoList &files) {
     );
 
     if(confirm == QMessageBox::Yes) {
-        caterNewThread(new DeleteThread(files));
+        DeleteThread *t = new DeleteThread(files);
+        t->progressBar->setIcons(deleteIcon, inverseDeleteIcon);
+        caterNewThread(t);
     }
 }
 
@@ -194,7 +200,11 @@ void FileOperator::copyFiles(const QFileInfoList &files, QDir &destination) {
     );
 
     if(confirm == QMessageBox::Yes) {
-        caterNewThread(new CopyThread(files, destination));
+        CopyThread *t = new CopyThread(files, destination);
+        t->progressBar->setIcons(copyIcon, inverseCopyIcon);
+        t->progressBar->fromText = shortenPath(files[0].absolutePath());
+        t->progressBar->toText = FileOperator::shortenPath(destination.absolutePath());
+        caterNewThread(t);
     }
 }
 
@@ -224,7 +234,11 @@ void FileOperator::moveFiles(const QFileInfoList &files, QDir &destination) {
     );
 
     if(confirm == QMessageBox::Yes) {
-        caterNewThread(new MoveThread(files, destination));
+        MoveThread *t = new MoveThread(files, destination);
+        t->progressBar->setIcons(moveIcon, inverseMoveIcon);
+        t->progressBar->fromText = shortenPath(files[0].absolutePath());
+        t->progressBar->toText = shortenPath(destination.absolutePath());
+        caterNewThread(t);
     }
 }
 
@@ -366,14 +380,24 @@ void FileOperator::updateProgress(FileManipulatorThread* manipulator, int value)
 }
 
 
+void FileOperator::updateMainText(FileManipulatorThread* manipulator, const QString &text) {
+    manipulator->progressBar->mainText = text;
+    manipulator->progressBar->mainText.remove(0, manipulator->progressBar->fromText.size() + 1);
+    manipulator->progressBar->repaint();
+}
+
+
 void FileOperator::showPaused(FileManipulatorThread* manipulator) {
-    manipulator->setText(0);
+    manipulator->progressBar->paused = true;
+    manipulator->progressBar->repaint();
 }
 
 
 void FileOperator::togglePauseOperation(FileManipulatorThread* manipulator) {
     if (manipulator->pause) {
         manipulator->pause = false;
+        manipulator->progressBar->paused = false;
+        manipulator->progressBar->repaint();
         manipulator->wake();
     } else {
         manipulator->pause = true;
@@ -393,7 +417,6 @@ void FileOperator::abortOperation(FileManipulatorThread* manipulator) {
     if(confirm == QMessageBox::Yes) {
         manipulator->abort = true;
         manipulator->pause = false;
-        manipulator->setText(0);
         manipulator->wake();
     }
 }
@@ -414,6 +437,8 @@ void FileOperator::caterNewThread(FileManipulatorThread *thread) {
         this, SLOT(setBarSize(FileManipulatorThread*, unsigned int)));
     connect(thread, SIGNAL(updateProgress(FileManipulatorThread*, int)),
         this, SLOT(updateProgress(FileManipulatorThread*, int)));
+    connect(thread, SIGNAL(updateFileName(FileManipulatorThread*, QString)),
+        this, SLOT(updateMainText(FileManipulatorThread*, QString)));
     connect(thread, SIGNAL(operationPaused(FileManipulatorThread*)),
         this, SLOT(showPaused(FileManipulatorThread*)));
 
@@ -422,7 +447,6 @@ void FileOperator::caterNewThread(FileManipulatorThread *thread) {
     connect(thread->progressBar, SIGNAL(abortOperation(FileManipulatorThread*)),
         this, SLOT(abortOperation(FileManipulatorThread*)));
 
-    thread->setText(0);
     layout()->addWidget(thread->progressBar);
     thread->start(QThread::LowestPriority);
 }
@@ -768,8 +792,7 @@ void FileManipulatorThread::updateProgress(int value) {
 
 void FileManipulatorThread::updateFile(const QString &name) {
     fileValue = 0;
-    fileName = FileOperator::shortenPath(name);
-    emit updateProgress(this, 0);
+    emit updateFileName(this, FileOperator::shortenPath(name));
 }
 
 
@@ -802,15 +825,6 @@ void FileManipulatorThread::setText(int value) {
             << ") by " << value << std::endl;
     }
 
-    if (!fileName.size()) {
-        if (pause) {
-            progressBar->setFormat(tr("Gathering information...") + " (" + tr("paused") + ")");
-        } else {
-            progressBar->setFormat(tr("Gathering information..."));
-        }
-        return;
-    }
     time_t now = time(0);
     if (lastTimeUpdate < now) {
         lastTimeUpdate = now;
@@ -828,10 +842,8 @@ void FileManipulatorThread::setText(int value) {
         }
     }
 
-    QString newFormat = barText.arg(fileName) + "\n%p%   ETA " + timeBuf;
-    if (pause) newFormat += " (" + tr("paused") + ")";
 
-    progressBar->setFormat(newFormat);
+    progressBar->setFormat(QString("%p%  ") + timeBuf);
     progressBar->setValue(progressBar->value() + value);
 }
 
index 2bf253e..076250d 100644 (file)
@@ -65,6 +65,7 @@ public slots:
     void remove(FileManipulatorThread* manipulator);
     void setBarSize(FileManipulatorThread* manipulator, unsigned int size);
     void updateProgress(FileManipulatorThread* manipulator, int value);
+    void updateMainText(FileManipulatorThread* manipulator, const QString &text);
     void showPaused(FileManipulatorThread* manipulator);
 
     void togglePauseOperation(FileManipulatorThread* manipulator);
@@ -74,6 +75,7 @@ protected:
     void caterNewThread(FileManipulatorThread *thread);
 
     QList<FileManipulatorThread*> manipulatorList;
+    QPixmap deleteIcon, inverseDeleteIcon, copyIcon, inverseCopyIcon, moveIcon, inverseMoveIcon;
 };
 
 
@@ -143,8 +145,8 @@ protected:
     // 1 for a file and file count for dirs (or both for copy&delete)
     QMap<QString, qint64> fileSizeMap;
 
-    // the name of the file thats being processed (for progressBar) and the text of the progressBar (the format)
-    QString fileName, barText;
+    // the text of the progressBar (the format)
+    QString barText;
     // stamp of the last ETA recalculation - done every second
     time_t lastTimeUpdate;
     time_t startTime, waitTime;
@@ -159,6 +161,7 @@ signals:
     void finished(FileManipulatorThread*);
     void setBarSize(FileManipulatorThread*, unsigned int);
     void updateProgress(FileManipulatorThread*, int);
+    void updateFileName(FileManipulatorThread*, QString);
     void operationPaused(FileManipulatorThread*);
 };
 
index cef767f..0a2dc65 100644 (file)
 #include <QApplication>
 
 #include "case.h"
+#include "style.h"
 
 
 int main(int argc, char* argv[]) {
     QApplication app(argc, argv);
+    app.setStyle(new Style());
+
     Case theCase;
 
     theCase.show();
index 29ad8da..29d68a6 100644 (file)
@@ -25,6 +25,7 @@
 
 ProgressBar::ProgressBar(FileManipulatorThread *thread, QWidget *parent) :
     QProgressBar(parent),
+    paused(false),
     contextEvent(false),
     thread(thread)
 {
@@ -35,8 +36,14 @@ ProgressBar::ProgressBar(FileManipulatorThread *thread, QWidget *parent) :
     barFont.setPointSize(12);
     setFont(barFont);
     setMinimumHeight(44);
-    setStyle(new QPlastiqueStyle);
-    //progressBar->setStyle(new QMotifStyle);
+    setFormat("");
+    mainText = tr("gathering information...");
+}
+
+
+void ProgressBar::setIcons(const QPixmap &icon, const QPixmap &inverseIcon) {
+    bgIcon = icon;
+    fgIcon = inverseIcon;
 }
 
 
index 90ba48b..fe67dfd 100644 (file)
@@ -19,6 +19,7 @@
 #define PROGRESSBAR_H
 
 #include <QProgressBar>
+#include <QIcon>
 
 
 class FileManipulatorThread;
@@ -33,6 +34,13 @@ signals:
 public:
     explicit ProgressBar(FileManipulatorThread *thread, QWidget *parent = 0);
 
+    void setIcons(const QPixmap &icon, const QPixmap &inverseIcon);
+
+    QString mainText, fromText, toText;
+    QPixmap bgIcon, fgIcon;
+    bool paused;
+
+
 protected:
     void mouseReleaseEvent(QMouseEvent *);
     void contextMenuEvent(QContextMenuEvent *);
diff --git a/src/style.cpp b/src/style.cpp
new file mode 100644 (file)
index 0000000..1d6e0f0
--- /dev/null
@@ -0,0 +1,197 @@
+// case - file manager for N900
+// Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
+// 
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "style.h"
+
+#include <QPainter>
+
+#include "progressbar.h"
+
+#include <iostream>
+
+
+void Style::drawControl(ControlElement element,
+    const QStyleOption *opt,
+    QPainter *p,
+    const QWidget *widget) const
+{
+    switch (element) {
+    case CE_ProgressBarGroove:
+        if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
+            p->setPen(opt->palette.color(QPalette::ButtonText).darker());
+            p->drawRoundedRect(pb->rect.adjusted(0, 0, -1, -1), 4, 4);
+        }
+        break;
+
+    case CE_ProgressBarLabel:
+        if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
+            QRect rect = pb->rect;
+            int maximum = pb->maximum;
+            int minimum = pb->minimum;
+            int value = pb->progress;
+
+            const ProgressBar *w = qobject_cast<const ProgressBar*>(widget);
+
+            float perc = (maximum - minimum) ?  static_cast<float>(value - minimum) / (maximum - minimum) : 0;
+
+            rect.adjust(2, 2, -2, -2);
+            QRect filledRect = rect, emptyRect = rect;
+            filledRect.setWidth(filledRect.width() * perc);
+            emptyRect.setX(emptyRect.x() + filledRect.width());
+
+            rect.adjust(3, 0, -3, 0);
+            QPoint iconPoint;
+            QRect topRect = rect, mainTextRect, bottomLeftRect = rect, bottomRightRect;
+            topRect.setHeight(topRect.height() / 2);
+            bottomLeftRect.setY(bottomLeftRect.y() + topRect.height());
+
+            int topRightWidth = p->fontMetrics().size(Qt::TextSingleLine, pb->text).width();
+            QRect pauseRect1(topRect.x() + topRect.width() - topRightWidth,
+                topRect.y() + topRect.height() / 2, 0, 0), pauseRect2;
+
+            if (w->paused) {
+                pauseRect1.adjust(-24, -7, -19, 7);
+                pauseRect2 = pauseRect1;
+                pauseRect2.adjust(10, 0, 10, 0);
+            }
+
+            if (w->fromText.size() || w->toText.size()) {
+                iconPoint = bottomLeftRect.center() - QPoint(10, 10);
+
+                mainTextRect = topRect;
+                mainTextRect.setRight(pauseRect1.x() - 10);
+
+                bottomRightRect = bottomLeftRect;
+                bottomLeftRect.setWidth(bottomLeftRect.width() / 2 - 13);
+                bottomRightRect.setX(bottomRightRect.x() + bottomLeftRect.width() + 26);
+            } else {
+                iconPoint = topRect.center() - QPoint(10, 8);
+
+                mainTextRect = bottomLeftRect;
+            }
+
+            QString mainText = shortenTextPath(p, mainTextRect, w->mainText);
+            QString bottomLeftText = shortenTextPath(p, bottomLeftRect, w->fromText);
+            QString bottomRightText = shortenTextPath(p, bottomRightRect, w->toText);
+
+            if (filledRect.width()) {
+                p->setClipRect(filledRect);
+                p->setPen(opt->palette.text().color());
+                p->setBrush(opt->palette.text());
+
+                p->drawPixmap(iconPoint, w->fgIcon);
+
+                p->drawText(mainTextRect, Qt::AlignCenter | Qt::TextSingleLine, mainText);
+                p->drawText(topRect, Qt::AlignRight | Qt::AlignVCenter | Qt::TextSingleLine, pb->text);
+                p->drawText(bottomLeftRect, Qt::AlignRight | Qt::AlignVCenter | Qt::TextSingleLine, bottomLeftText);
+                p->drawText(bottomRightRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, bottomRightText);
+
+                if (w->paused) {
+                    p->drawRect(pauseRect1);
+                    p->drawRect(pauseRect2);
+                }
+            }
+
+            if (emptyRect.width()) {
+                p->setClipRect(emptyRect);
+                p->setPen(opt->palette.buttonText().color());
+                p->setBrush(opt->palette.buttonText());
+
+                p->drawPixmap(iconPoint, w->bgIcon);
+
+                p->drawText(mainTextRect, Qt::AlignCenter | Qt::TextSingleLine, mainText);
+                p->drawText(topRect, Qt::AlignRight | Qt::AlignVCenter | Qt::TextSingleLine, pb->text);
+                p->drawText(bottomLeftRect, Qt::AlignRight | Qt::AlignVCenter | Qt::TextSingleLine, bottomLeftText);
+                p->drawText(bottomRightRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, bottomRightText);
+
+                if (w->paused) {
+                    p->drawRect(pauseRect1);
+                    p->drawRect(pauseRect2);
+                }
+            }
+        }
+        break;
+
+    case CE_ProgressBarContents:
+        if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
+            QRect rect = pb->rect;
+            int maximum = pb->maximum;
+            int minimum = pb->minimum;
+            int value = pb->progress;
+
+            QPalette pal = pb->palette;
+            // Correct the highlight color if it is the same as the background
+            if (pal.highlight() == pal.background())
+                pal.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
+                                                                     QPalette::Highlight));
+
+            float perc = (maximum - minimum) ?  static_cast<float>(value - minimum) / (maximum - minimum) : 0;
+
+            QRect filledRect = rect;
+            filledRect.adjust(2, 2, -2, -2);
+            filledRect.setWidth(filledRect.width() * perc);
+
+            QColor highlight = opt->palette.highlight().color();
+            QColor lighter = highlight.lighter(120);
+            QColor darker = highlight.darker(110);
+
+            QGradientStops stops;
+            stops << QGradientStop(0.00, lighter);
+            stops << QGradientStop(0.15, darker);
+            stops << QGradientStop(0.80, darker);
+            stops << QGradientStop(1.00, lighter);
+            QLinearGradient fillGrad(0, 0, 0, filledRect.height());
+            fillGrad.setStops(stops);
+            QBrush fillBrush(fillGrad);
+
+            p->setPen(lighter);
+            p->setBrush(fillBrush);
+            p->drawRoundedRect(filledRect.adjusted(0, 0, -1, -1), 2, 2);
+        }
+        break;
+        
+    default:
+        QMaemo5Style::drawControl(element, opt, p, widget);
+    }
+}
+
+
+QString Style::shortenTextPath(QPainter *p, const QRect &r, QString s) const {
+    QFontMetrics m = p->fontMetrics();
+    int width = r.width();
+    int start = -2, end = 1;
+
+    while (m.size(Qt::TextSingleLine, s).width() > width && s.size() > 7) {
+        if (end <= 0) {
+            start = end + 7;
+        } else {
+            // first pass only
+            if (start == -2) {
+                start = s.lastIndexOf('/', -2);
+                if (start <= 0) start += 4;
+                end = s.lastIndexOf('/', start - 1);
+            } else {
+                start = end + 4;
+                end = s.lastIndexOf('/', end - 1);
+            }
+        }
+
+        s.replace(end + 1, start - end - 1, "...");
+    }
+
+    return s;
+}
diff --git a/src/style.h b/src/style.h
new file mode 100644 (file)
index 0000000..28068e5
--- /dev/null
@@ -0,0 +1,37 @@
+// case - file manager for N900
+// Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
+// 
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef STYLE_H
+#define STYLE_H
+
+#include <QMaemo5Style>
+
+
+class Style : public QMaemo5Style {
+    Q_OBJECT
+
+public:
+    void drawControl(ControlElement element,
+        const QStyleOption *option,
+        QPainter *painter,
+        const QWidget *widget) const;
+
+private:
+    QString shortenTextPath(QPainter *p, const QRect &r, QString s) const;
+};
+
+#endif // STYLE_H
diff --git a/src/utils.cpp b/src/utils.cpp
new file mode 100644 (file)
index 0000000..bf082e0
--- /dev/null
@@ -0,0 +1,67 @@
+// case - file manager for N900
+// Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
+// 
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "utils.h"
+
+
+void themeImage(const QPalette &p, QImage &image, const bool inverse) {
+    image = image.convertToFormat(QImage::Format_Indexed8);
+
+    QRgb highlight = p.highlight().color().rgb();
+    QRgb second;
+    if (inverse) {
+        second = p.text().color().rgb();
+    } else {
+        second = p.buttonText().color().rgb();
+    }
+
+    QVector<QRgb> colorTable = image.colorTable();
+    for (QVector<QRgb>::iterator it = colorTable.begin(); it != colorTable.end(); ++it) {
+        if ((*it & 0xFFFFFF) == 0xFFFFFF) *it = (*it & 0xFF000000) | second;
+        else if ((*it & 0xFFFFFF) == 0x0000FF) *it = (*it & 0xFF000000) | highlight;
+    }
+    image.setColorTable(colorTable);
+}
+
+
+bool loadOperationIcons(const QPalette &p, const QString &name, QPixmap &normal, QPixmap &inverse) {
+    QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM");
+    if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG");
+    if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF");
+
+    QImage inverseIconImage = iconImage;
+
+    themeImage(p, iconImage, false);
+    themeImage(p, inverseIconImage, true);
+
+    normal = QPixmap::fromImage(iconImage);
+    inverse = QPixmap::fromImage(inverseIconImage);
+    return true;
+}
+
+
+bool loadMiddleButtonIcons(const QPalette &p, const QString &name, QIcon &normal, QIcon &mirrored) {
+    QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM");
+    if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG");
+    if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF");
+
+    themeImage(p, iconImage, false);
+
+    normal = QIcon(QPixmap::fromImage(iconImage));
+    mirrored = QIcon(QPixmap::fromImage(iconImage.mirrored(true, false)));
+    return true;
+}
diff --git a/src/utils.h b/src/utils.h
new file mode 100644 (file)
index 0000000..b3e1654
--- /dev/null
@@ -0,0 +1,33 @@
+// case - file manager for N900
+// Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
+// 
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef UTILS_H
+#define UTILS_H
+
+#include <QPalette>
+#include <QPixmap>
+#include <QIcon>
+
+
+#define ICON_PATH QString("/usr/share/pixmaps/case/")
+#define ICON_SET "default"
+
+
+bool loadOperationIcons(const QPalette &p, const QString &name, QPixmap &normal, QPixmap &inverse);
+bool loadMiddleButtonIcons(const QPalette &p, const QString &name, QIcon &normal, QIcon &mirrored);
+
+#endif // UTILS_H