├── README.md ├── deployment.pri ├── imagequick.desktop ├── imagequick.pro ├── imagequick_harmattan.desktop ├── images └── imagequick.svg ├── main.cpp ├── qml ├── EditBox.qml ├── Help.qml ├── HelpItem.qml ├── History.js ├── ImageItem.qml ├── ImageLabel.qml ├── ImageView.qml ├── Osd.qml ├── Picture.qml ├── Popup.qml ├── Scrollable.qml ├── Storage.js └── main.qml └── resource.qrc /README.md: -------------------------------------------------------------------------------- 1 | ImageQuick 2 | ========== 3 | 4 | ImageQuick is simple image viewer. 5 | 6 | Usage 7 | ----- 8 | 9 | imagequick [filename|directory|url] 10 | Opens image or directory or images in Atom/RSS feed. 11 | imagequick -S [filename|directory|url] 12 | Restores/saves session . 13 | 14 | Shortcuts 15 | --------- 16 | 17 | * **Arrow keys, Page Up, Page Down, Spacebar**: basic navigation 18 | * **N, J**: next item 19 | * **B, K, SHIFT + N**: previous item 20 | * **Home or End**: first or last item 21 | * **\+ or -**: zoom in or out 22 | * **W or H**: fit to width or height 23 | * **Period**: zoom to fill 24 | * **/**: zoom to fit 25 | * **Asterisk**: original zoom (1x) 26 | * **O**: change orientation 27 | * **Enter**: enter directory or show single or multiple items 28 | * **Control + F, Apostrophe**: filter items 29 | * **Backspace**: show all items (disable filter) or go to parent directory 30 | * **C**: copy URL 31 | * **Escape, Q**: exit 32 | * **A, Z**: sharpen/unsharpen image 33 | 34 | Examples 35 | -------- 36 | Open single image. 37 | 38 | imagequick image.png 39 | 40 | Browse directory and save session as 'default'. 41 | 42 | imagequick -sdefault MyPictures 43 | 44 | Next time you can just run 45 | 46 | imagequick -sdefault 47 | 48 | to resume browsing from the last time. 49 | 50 | Browse Flickr gallery. 51 | 52 | imagequick -sflickr 'http://api.flickr.com/services/feeds/photos_public.gne?format=rss2' 53 | 54 | Browse Daily Deviations on deviantART. 55 | 56 | imagequick -sdeviant 'http://backend.deviantart.com/rss.xml?q=special%3Add&type=deviation&offset=0' 57 | 58 | -------------------------------------------------------------------------------- /deployment.pri: -------------------------------------------------------------------------------- 1 | android-no-sdk { 2 | target.path = /data/user/qt 3 | export(target.path) 4 | INSTALLS += target 5 | } else:android { 6 | x86 { 7 | target.path = /libs/x86 8 | } else: armeabi-v7a { 9 | target.path = /libs/armeabi-v7a 10 | } else { 11 | target.path = /libs/armeabi 12 | } 13 | export(target.path) 14 | INSTALLS += target 15 | } else:unix { 16 | isEmpty(target.path) { 17 | qnx { 18 | target.path = /tmp/$${TARGET}/bin 19 | } else { 20 | target.path = /opt/$${TARGET}/bin 21 | } 22 | export(target.path) 23 | } 24 | INSTALLS += target 25 | } 26 | 27 | export(INSTALLS) 28 | -------------------------------------------------------------------------------- /imagequick.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Encoding=UTF-8 3 | Version=1.0 4 | Type=Application 5 | Terminal=false 6 | Name=imagequick 7 | Exec=imagequick 8 | Icon=imagequick 9 | X-Window-Icon= 10 | X-HildonDesk-ShowInToolbar=true 11 | X-Osso-Type=application/x-executable 12 | -------------------------------------------------------------------------------- /imagequick.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | 5 | CONFIG += c++11 6 | 7 | SOURCES += main.cpp 8 | 9 | # PREFIX=/usr/local -- set install prefix 10 | # STANDALONE=1 -- compile single binary 11 | isEqual(STANDALONE,1) { 12 | # Compile application without any external images or QMLs. 13 | RESOURCES += resource.qrc 14 | DEFINES += IMAGEQUICK_STANDALONE 15 | } else { 16 | # Add more folders to ship with the application, here 17 | folder_qml.files = qml 18 | folder_images.files = images/imagequick.svg 19 | folder_images.path = images 20 | INSTALLS = folder_qml folder_images 21 | } 22 | 23 | # Additional import path used to resolve QML modules in Qt Creator's code model 24 | QML_IMPORT_PATH = 25 | 26 | # Install -- qmake PREFIX=/usr/local 27 | !isEmpty(PREFIX) { 28 | unix:!macx { 29 | target.path = $$PREFIX/bin 30 | DEFINES += INSTALL_PREFIX=\\\"$$PREFIX\\\" 31 | 32 | !isEqual(STANDALONE,1) { 33 | INSTALL_DATA_PATH = share/imagequick 34 | INSTALL_ICON_PATH = share/icons/hicolor/scalable/apps 35 | 36 | folder_qml.path = $$PREFIX/$$INSTALL_DATA_PATH 37 | folder_images.path = $$PREFIX/$$INSTALL_ICON_PATH 38 | desktop.files = imagequick.desktop 39 | desktop.path = $$PREFIX/share/applications 40 | 41 | INSTALLS += desktop 42 | 43 | DEFINES += INSTALL_DATA_PATH=\\\"$$INSTALL_DATA_PATH\\\" 44 | DEFINES += INSTALL_ICON_PATH=\\\"$$INSTALL_ICON_PATH\\\" 45 | } 46 | } 47 | } 48 | 49 | include(deployment.pri) 50 | -------------------------------------------------------------------------------- /imagequick_harmattan.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Encoding=UTF-8 3 | Version=1.0 4 | Type=Application 5 | Terminal=false 6 | Name=imagequick 7 | Exec=/usr/bin/single-instance /opt/imagequick/bin/imagequick 8 | Icon=/usr/share/icons/hicolor/80x80/apps/imagequick80.png 9 | X-Window-Icon= 10 | X-HildonDesk-ShowInToolbar=true 11 | X-Osso-Type=application/x-executable 12 | -------------------------------------------------------------------------------- /images/imagequick.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 22 | 24 | 28 | 32 | 36 | 37 | 39 | 43 | 47 | 51 | 55 | 59 | 60 | 62 | 66 | 70 | 74 | 75 | 77 | 81 | 85 | 89 | 90 | 92 | 96 | 100 | 104 | 105 | 107 | 111 | 115 | 119 | 120 | 122 | 126 | 130 | 134 | 138 | 142 | 143 | 154 | 164 | 169 | 174 | 180 | 184 | 185 | 196 | 207 | 218 | 229 | 230 | 249 | 256 | 257 | 259 | 260 | 262 | image/svg+xml 263 | 265 | 266 | 267 | 268 | 269 | 274 | 284 | 294 | 304 | 314 | 324 | 334 | 344 | 350 | 356 | 357 | 358 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #define VERSION "0.2.0" 11 | 12 | using std::endl; 13 | 14 | void printHelp(const char *cmd) 15 | { 16 | std::cout << "Usage:" << endl 17 | << " " << cmd << " [filename|directory|url]" << endl 18 | << " Opens image or directory or images in Atom/RSS feed." << endl 19 | << " " << cmd << " -S [filename|directory|url]" << endl 20 | << " Restores/saves session ." << endl 21 | << endl 22 | << "ImageQuick v" VERSION << " (hluk@email.cz)" << endl; 23 | } 24 | 25 | int main(int argc, char *argv[]) 26 | { 27 | // Create Qt GUI application. 28 | QGuiApplication app(argc, argv); 29 | 30 | // Parse command line arguments. 31 | QString src; 32 | QString session; 33 | QString filename; 34 | bool sessionNext = false; 35 | bool filenameNext = false; 36 | 37 | for ( const auto &arg : QGuiApplication::arguments().mid(1) ) { 38 | if ( sessionNext ) { 39 | session = arg; 40 | sessionNext = false; 41 | filenameNext = true; 42 | } else if ( !filenameNext && session.isEmpty() && arg.startsWith("-s", Qt::CaseInsensitive) ) { 43 | if (arg.length() == 2) 44 | sessionNext = true; 45 | else 46 | session = arg.right( arg.length()-2 ); 47 | filenameNext = true; 48 | } else if ( !filenameNext && (arg == QString("-") || arg == QString("--")) ) { 49 | filenameNext = true; 50 | } else if ( !filenameNext && (arg == QString("-h") || arg == QString("--help")) ) { 51 | printHelp(argv[0]); 52 | return 0; 53 | } else if ( src.isEmpty() ) { 54 | src = arg; 55 | } else { 56 | printHelp(argv[0]); 57 | return 1; 58 | } 59 | } 60 | 61 | QQmlApplicationEngine engine; 62 | 63 | QQmlContext *context = engine.rootContext(); 64 | 65 | // Browse URL from arguments or current directory. 66 | if ( src.isEmpty() ) { 67 | context->setContextProperty( "currentPath", "file://" + QDir::currentPath() ); 68 | } else { 69 | if ( QFile::exists(src) ) { 70 | QDir dir(src); 71 | if ( !dir.exists() ) { 72 | filename = dir.dirName(); 73 | dir.cdUp(); 74 | } 75 | src = "file://" + dir.absolutePath(); 76 | } 77 | } 78 | 79 | // Set up properties. 80 | context->setContextProperty("src", src); 81 | context->setContextProperty("session", session); 82 | context->setContextProperty("filename", filename); 83 | 84 | #if defined(IMAGEQUICK_STANDALONE) 85 | const QUrl mainQml("qrc:/qml/qml/main.qml"); 86 | const QIcon icon(":/images/logo"); 87 | #elif defined(INSTALL_PREFIX) 88 | const QUrl mainQml(INSTALL_PREFIX "/" INSTALL_DATA_PATH "/qml/main.qml"); 89 | const QIcon icon(INSTALL_PREFIX "/" INSTALL_ICON_PATH "/imagequick.svg"); 90 | #else 91 | const QString sharePath = QGuiApplication::applicationDirPath(); 92 | const QUrl mainQml(sharePath + "/qml/main.qml"); 93 | const QIcon icon(sharePath + "/images/imagequick.svg"); 94 | #endif 95 | 96 | engine.load(mainQml); 97 | app.setWindowIcon(icon); 98 | 99 | return app.exec(); 100 | } 101 | -------------------------------------------------------------------------------- /qml/EditBox.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | 3 | Popup { 4 | color: "white" 5 | width: row.width + 20 6 | height: edit.height+10 7 | 8 | signal changed(string text) 9 | signal accepted(string text) 10 | signal rejected() 11 | 12 | property alias text: edit.text 13 | property alias label: editlabel.text 14 | 15 | function accept() { 16 | if (timer.running) { 17 | changed(text); 18 | timer.stop(); 19 | } 20 | accepted(text); 21 | close(); 22 | } 23 | 24 | function reject() { 25 | if (timer.running) { 26 | changed(text); 27 | timer.stop(); 28 | } 29 | rejected(); 30 | close(); 31 | edit.text = ""; 32 | } 33 | 34 | function copyAll() { 35 | edit.selectAll(); 36 | edit.copy(); 37 | } 38 | 39 | Row { 40 | id: row 41 | anchors.centerIn: parent 42 | spacing: 10 43 | 44 | Text { 45 | id: editlabel 46 | color: "#444" 47 | font { 48 | pixelSize: 16 49 | bold: true 50 | } 51 | } 52 | 53 | TextInput { 54 | id: edit 55 | cursorVisible: true 56 | color: "#151515" 57 | selectionColor: "Green" 58 | width: Math.max(100, 59 | Math.min(implicitWidth, row.parent.parent.width - editlabel.width - 40)) 60 | 61 | font { 62 | pixelSize: 16 63 | } 64 | onTextChanged: { 65 | timer.running = true 66 | } 67 | Timer { 68 | id: timer 69 | interval: 500 70 | running: false 71 | repeat: false 72 | onTriggered: changed(text) 73 | } 74 | } 75 | } 76 | 77 | onShown: { 78 | edit.focus = true; 79 | edit.selectAll(); 80 | } 81 | 82 | Keys.forwardTo: [returnKey, edit] 83 | Item { 84 | id: returnKey 85 | Keys.onReturnPressed: accept() 86 | Keys.onEnterPressed: accept() 87 | Keys.onEscapePressed: reject() 88 | Keys.onPressed: event.accepted = true 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /qml/Help.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | 3 | Popup { 4 | width: help.width + 16 5 | height: help.height + 16 6 | popupOpacity: 0.9 7 | 8 | Column { 9 | id: help 10 | spacing: 2 11 | anchors.centerIn: parent 12 | 13 | HelpItem { label: qsTr("Navigation") } 14 | HelpItem { 15 | label: qsTr("Arrow Keys") 16 | help: qsTr("Movement") 17 | } 18 | HelpItem { 19 | label: qsTr("Home End") 20 | help: qsTr("First/Last Item") 21 | } 22 | HelpItem { 23 | label: qsTr("Page Down/Up") 24 | help: qsTr("Next/Previous Page") 25 | } 26 | HelpItem { 27 | label: qsTr("Space") 28 | help: qsTr("Scroll Down") 29 | } 30 | HelpItem { 31 | label: qsTr("J N") 32 | help: qsTr("Next Item") 33 | } 34 | HelpItem { 35 | label: qsTr("K P B Shift+N") 36 | help: qsTr("Previous Item") 37 | } 38 | HelpItem { 39 | label: qsTr("Ctrl+D Ctrl+L") 40 | help: qsTr("Go to URL") 41 | } 42 | 43 | HelpItem { label: qsTr("General") } 44 | HelpItem { 45 | label: qsTr("F1 ?") 46 | help: qsTr("Help") 47 | } 48 | HelpItem { 49 | label: qsTr("F") 50 | help: qsTr("Toggle Fullscreen") 51 | } 52 | HelpItem { 53 | label: qsTr("Ctrl+F '") 54 | help: qsTr("Filter Items") 55 | } 56 | HelpItem { 57 | label: qsTr("O") 58 | help: qsTr("Horizontal/Vertical Layout") 59 | } 60 | HelpItem { 61 | label: qsTr("Escape Q") 62 | help: qsTr("Quit") 63 | } 64 | HelpItem { 65 | label: qsTr("Ctrl+R F5") 66 | help: qsTr("Reload") 67 | } 68 | HelpItem { 69 | label: qsTr("Enter") 70 | help: qsTr("Select") 71 | } 72 | HelpItem { 73 | label: qsTr("Backspace") 74 | help: qsTr("Back") 75 | } 76 | 77 | HelpItem { label: qsTr("Effects") } 78 | HelpItem { 79 | label: qsTr("+ -") 80 | help: qsTr("Zoom In/Out") 81 | } 82 | HelpItem { 83 | label: qsTr(". /") 84 | help: qsTr("Zoom to Fill/Fit") 85 | } 86 | HelpItem { 87 | label: qsTr("H W") 88 | help: qsTr("Fit to Height/Width") 89 | } 90 | HelpItem { 91 | label: qsTr("A Z") 92 | help: qsTr("Sharpen/Unsharpen") 93 | } 94 | } 95 | 96 | Keys.onPressed: { 97 | // close on any key 98 | close(); 99 | 100 | // propagate some keys to parent 101 | var k = event.key; 102 | if (k === Qt.Key_F1 || k === Qt.Key_Question || k === Qt.Key_Escape 103 | || k === Qt.Key_Enter || k === Qt.Key_Return) { 104 | event.accepted = true; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /qml/HelpItem.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | 3 | Row { 4 | property alias label: labelText.text 5 | property alias help: helpText.text 6 | 7 | property bool isHeader: help === "" 8 | 9 | anchors.horizontalCenter: parent.horizontalCenter 10 | 11 | Text { 12 | id: labelText 13 | color: isHeader ? "#666" : "#333" 14 | font { 15 | bold: true 16 | pointSize: isHeader ? 14 : 12 17 | } 18 | } 19 | 20 | Text { 21 | text: " ... " 22 | opacity: isHeader ? 0 : 1 23 | color: "black" 24 | font.pointSize: 12 25 | } 26 | 27 | Text { 28 | id: helpText 29 | color: "black" 30 | font.pointSize: 12 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /qml/History.js: -------------------------------------------------------------------------------- 1 | var _history = []; 2 | 3 | function setHistory(history) { 4 | if (history instanceof Array) 5 | _history = history; 6 | else 7 | _history = []; 8 | } 9 | 10 | function getHistory(history) { 11 | return _history; 12 | } 13 | 14 | function last() { 15 | return _history[_history.length-1] || 0; 16 | } 17 | 18 | function set(item) { 19 | _history[_history.length ? _history.length-1 : 0] = item; 20 | } 21 | 22 | function push(item) { 23 | _history.push(item); 24 | } 25 | 26 | function pop() { 27 | return _history.pop(); 28 | } 29 | -------------------------------------------------------------------------------- /qml/ImageItem.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | 3 | Item { 4 | id: item 5 | 6 | property bool isImage: image.status !== Image.Error 7 | 8 | opacity: isHidden ? 0.0 : 1.0 9 | scale: opacity 10 | 11 | width: opacity * 12 | Math.max( image.width, label.width, 13 | ((page.one || !page.horizontal) ? view.width : 0) ) 14 | height: opacity * 15 | Math.max( image.height, label.height, 16 | ((page.one || page.horizontal) ? view.height : 0) ) 17 | 18 | Behavior on opacity { 19 | NumberAnimation { 20 | duration: showDuration 21 | } 22 | } 23 | 24 | MouseArea { 25 | anchors.fill: parent 26 | onClicked: { 27 | select(itemIndex) 28 | } 29 | onDoubleClicked: { 30 | select(itemIndex) 31 | forward() 32 | } 33 | } 34 | 35 | Picture { 36 | id: image 37 | } 38 | 39 | ShaderEffect { 40 | id: shaderSharpen 41 | property variant tex: ShaderEffectSource { 42 | sourceItem: image 43 | hideSource: true 44 | } 45 | property real w: 1.0/image.width 46 | property real h: 1.0/image.height 47 | property real strength: sharpenStrength 48 | anchors.fill: image 49 | blending: false; 50 | 51 | fragmentShader: " 52 | varying highp vec2 qt_TexCoord0; 53 | uniform sampler2D tex; 54 | uniform highp float w; 55 | uniform highp float h; 56 | uniform highp float strength; 57 | 58 | void main(void) 59 | { 60 | vec2 xy = qt_TexCoord0.xy; 61 | vec4 col = 9.0 * texture2D(tex, xy); 62 | 63 | col -= texture2D(tex, xy + vec2(-w, h)); 64 | col -= texture2D(tex, xy + vec2(0.0, h)); 65 | col -= texture2D(tex, xy + vec2(w, h)); 66 | col -= texture2D(tex, xy + vec2(-w, 0.0)); 67 | 68 | col -= texture2D(tex, xy + vec2(w, 0.0)); 69 | col -= texture2D(tex, xy + vec2(0.0, -h)); 70 | col -= texture2D(tex, xy + vec2(w, -h)); 71 | col -= texture2D(tex, xy + vec2(-w, -h)); 72 | col = col * strength + (1.0 - strength) * texture2D(tex, xy); 73 | gl_FragColor = col; 74 | } 75 | " 76 | } 77 | 78 | ImageLabel { 79 | id: label 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /qml/ImageLabel.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | 3 | Item { 4 | width: labelText.width+40 5 | height: labelText.height+10 6 | Text { 7 | id: labelText 8 | anchors.horizontalCenter: parent.horizontalCenter 9 | visible: !page.one || image.status !== Image.Ready 10 | color: isCurrent ? page.colorCurrent : isDirectory() ? page.colorDirectory : isImage ? page.colorImage : page.colorOther 11 | text: "" + (itemTitle() || filename()) + "" + 12 | (image.status === Image.Loading ? 13 | "
"+parseInt(100*image.progress)+"% loaded" : 14 | (image.status === Image.Ready ? 15 | "
"+(itemWidth()||image.implicitWidth)+"x"+(itemHeight()||image.implicitHeight)+"" : 16 | "")) 17 | 18 | style: Text.Outline 19 | styleColor: "black" 20 | 21 | font { 22 | pixelSize: 16 23 | underline: isCurrent && isDirectory() 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /qml/ImageView.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | import QtQuick.XmlListModel 2.0 3 | import Qt.labs.folderlistmodel 1.0 4 | import "History.js" as History 5 | 6 | Scrollable { 7 | id: view 8 | 9 | property real zoom: 1.0 10 | property FolderListModel newFileModel: null 11 | property XmlListModel newXmlModel: null 12 | property real sharpenStrength: 0.0 13 | 14 | flickableDirection: Flickable.HorizontalAndVerticalFlick 15 | 16 | function source() { 17 | return newFileModel ? 18 | newFileModel.folder : 19 | newXmlModel ? 20 | newXmlModel.source : 21 | undefined; 22 | } 23 | 24 | function isLocal(path) { 25 | return ("" + path).slice(0, 7) === "file://"; 26 | } 27 | 28 | function setSource(path) { 29 | if (("" + path).slice(0, 1) === "/") 30 | path = "file://" + path; 31 | if ( isLocal(path) ) { 32 | newXmlModel = null; 33 | newFileModel = fileModelComponent.createObject(view, {folder: path}); 34 | } else { 35 | newFileModel = null; 36 | newXmlModel = xmlModelComponent.createObject(view, {source: path}); 37 | } 38 | newModelTimer.start(); 39 | } 40 | 41 | function goTo(path) { 42 | History.push(0); 43 | setSource(path); 44 | page.filter = ""; 45 | } 46 | 47 | function isItemDirectory(index) { 48 | return newFileModel !== null && model.isFolder(index); 49 | } 50 | 51 | function select(index) { 52 | History.set(index); 53 | currentIndex = index; 54 | } 55 | 56 | function current() { 57 | return History.last(); 58 | } 59 | 60 | function back() { 61 | /* show multiple items or go to parent folder*/ 62 | if (page.one) { 63 | page.one = false; 64 | page.single = ""; 65 | } else { 66 | if (page.filter) { 67 | page.filter = ""; 68 | } else if (newFileModel) { 69 | History.pop(); 70 | setSource(view.model.parentFolder); 71 | } 72 | } 73 | } 74 | 75 | function forward() { 76 | /* enter folder or show single image */ 77 | if ( currentItem.isDirectory() ) { 78 | goTo( currentItem.path() ); 79 | } else { 80 | if (currentItem.isImage) { 81 | page.one = !page.one; 82 | page.single = ""; 83 | positionViewAtIndex(currentIndex, ListView.Contain); 84 | } 85 | } 86 | } 87 | 88 | function setHistory(history) { 89 | History.setHistory(history); 90 | } 91 | 92 | function getHistory() { 93 | return History.getHistory(); 94 | } 95 | 96 | function next() { 97 | /* focus next visible item */ 98 | var i = currentIndex; 99 | while(currentIndex+1 < count) { 100 | incrementCurrentIndex(); 101 | if (!currentItem.isHidden) 102 | break; 103 | } 104 | select(currentItem.isHidden ? i : currentIndex); 105 | } 106 | 107 | function previous() { 108 | /* focus previous visible item */ 109 | var i = currentIndex; 110 | while(currentIndex > 0) { 111 | decrementCurrentIndex(); 112 | if (!currentItem.isHidden) 113 | break; 114 | } 115 | select(currentItem.isHidden ? i : currentIndex); 116 | } 117 | 118 | function reload() { 119 | if (newXmlModel) 120 | model.reload(); 121 | else 122 | setSource(model.folder); 123 | } 124 | 125 | state: "FIT" 126 | 127 | Behavior on zoom { 128 | NumberAnimation { 129 | duration: page.zoomDuration 130 | easing.type: Easing.OutQuad; 131 | } 132 | } 133 | 134 | /* model */ 135 | Timer { 136 | id: newModelTimer 137 | interval: 100; running:false; repeat: false 138 | onTriggered: { 139 | if (newFileModel) { 140 | model = newFileModel; 141 | cacheBuffer = 0; 142 | } else { 143 | model = newXmlModel; 144 | cacheBuffer = 4096; 145 | } 146 | } 147 | } 148 | Component { 149 | id: fileModelComponent 150 | FolderListModel { 151 | id: fileModel 152 | sortField: FolderListModel.Name 153 | showDirs: page.single === "" 154 | nameFilters: page.single ? [page.single] : [] 155 | } 156 | } 157 | Component { 158 | id: xmlModelComponent 159 | XmlListModel { 160 | id: xmlModel 161 | query: "/rss/channel/item" 162 | namespaceDeclarations: "declare namespace media=\"http://search.yahoo.com/mrss/\";" 163 | 164 | XmlRole { name: "itemTitle"; query: "title/string()" } 165 | /* filePath is last thumbnail */ 166 | XmlRole { name: "filePath"; query: "(*|.)/media:thumbnail[last()]/@url/string()" } 167 | /* filePathBig is last content (maybe bigger image) */ 168 | XmlRole { name: "filePathBig"; query: "(*|.)/media:content[last()]/@url/string()" } 169 | XmlRole { name: "itemWidth"; query: "(*|.)/media:content[last()]/@width/string()" } 170 | XmlRole { name: "itemHeight"; query: "(*|.)/media:content[last()]/@height/string()" } 171 | } 172 | } 173 | 174 | /* delegate */ 175 | property string fileName: "" 176 | property string filePath: "" 177 | property string filePathBig: "" 178 | property string title: "" 179 | property int itemWidth: 0 180 | property int itemHeight: 0 181 | delegate: ImageItem { 182 | function path(hires) { 183 | var url = hires && filePathBig || filePath || ""; 184 | if (url.slice(0, 1) === "/") 185 | url = "file://" + url; 186 | return url; 187 | } 188 | function filename() { return fileName || filePath || ""; } 189 | function itemTitle() { return title || ""; } 190 | function itemIndex() { return index; } 191 | function itemWidth() { return newXmlModel ? itemWidth : 0; } 192 | function itemHeight() { return newXmlModel ? itemHeight : 0; } 193 | function isDirectory() { return isItemDirectory(index); } 194 | property bool isCurrent: ListView.isCurrentItem 195 | property bool isHidden: !page.isMatched(filename(), page.filter) 196 | } 197 | 198 | /* progress */ 199 | Osd { 200 | id: progress 201 | anchors.right: parent.right 202 | anchors.bottom: parent.bottom 203 | text: (currentIndex+1) + "/" + count 204 | } 205 | 206 | /* sharpen label */ 207 | Osd { 208 | id: labelSharpen 209 | anchors.left: parent.left 210 | anchors.bottom: parent.bottom 211 | text: "sharpen: " + Math.round(sharpenStrength*100) + " %" 212 | } 213 | 214 | /* zoom label */ 215 | Osd { 216 | id: labelZoom 217 | anchors.right: parent.right 218 | anchors.top: parent.top 219 | text: "zoom: " + Math.round(zoom*100) + " %" 220 | } 221 | 222 | onCountChanged: { 223 | var last = History.last(); 224 | if (currentIndex !== last && last < count) { 225 | positionViewAtIndex(last, ListView.Beginning); 226 | currentIndex = last; 227 | } 228 | } 229 | 230 | onOrientationChanged: { 231 | if (currentIndex >= 0) 232 | positionViewAtIndex(currentIndex, ListView.Contain); 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /qml/Osd.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | 3 | Text { 4 | id: osd 5 | anchors.margins: 6 6 | color: "white" 7 | style: Text.Outline 8 | styleColor: "black" 9 | opacity: 0 10 | 11 | font { 12 | pixelSize: 16 13 | bold: true 14 | } 15 | 16 | Behavior on text { 17 | SequentialAnimation { 18 | running: false 19 | NumberAnimation { 20 | target: osd 21 | property: "opacity" 22 | to: 0.7 23 | duration: 500 24 | } 25 | NumberAnimation { 26 | target: osd 27 | property: "opacity" 28 | to: 0.0 29 | duration: 6000 30 | easing.type: Easing.InQuint 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /qml/Picture.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | 3 | AnimatedImage { 4 | id: image 5 | source: ((isHidden || isDirectory()) && status !== Image.Ready) ? "" : path(page.one) 6 | anchors.centerIn: parent 7 | 8 | property real izoom: 1.0 9 | 10 | width: implicitWidth * izoom * zoom 11 | height: implicitHeight * izoom * zoom 12 | smooth: true 13 | asynchronous: true 14 | 15 | Behavior on izoom { 16 | NumberAnimation { 17 | duration: 250 18 | easing.type: Easing.OutQuad; 19 | } 20 | } 21 | 22 | /* ZOOM */ 23 | states: [ 24 | State { 25 | when: view.state === "NORMAL" 26 | PropertyChanges { 27 | target: image 28 | izoom: 1.0 29 | } 30 | }, 31 | State { 32 | when: view.state === "FIT" 33 | PropertyChanges { 34 | target: image 35 | izoom: Math.min(1.0, view.width/implicitWidth, 36 | view.height/implicitHeight) 37 | } 38 | }, 39 | State { 40 | when: view.state === "FILL" 41 | PropertyChanges { 42 | target: image 43 | izoom: Math.max(1.0, view.width/implicitWidth, 44 | view.height/implicitHeight) 45 | } 46 | }, 47 | State { 48 | when: view.state === "FIT-TO-WIDTH" 49 | PropertyChanges { 50 | target: image 51 | izoom: Math.min(implicitWidth, view.width)/implicitWidth 52 | } 53 | }, 54 | State { 55 | when: view.state === "FIT-TO-HEIGHT" 56 | PropertyChanges { 57 | target: image 58 | izoom: Math.min(implicitHeight, view.height)/implicitHeight 59 | } 60 | } 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /qml/Popup.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | 3 | Rectangle { 4 | anchors.centerIn: parent 5 | color: "#ddd" 6 | border.color: "#333" 7 | border.width: 2 8 | radius: 6 9 | smooth: true 10 | opacity: 0 11 | 12 | property real popupOpacity: 1 13 | 14 | signal shown() 15 | signal closed() 16 | 17 | function show() { 18 | opacity = popupOpacity; 19 | focus = true; 20 | shown(); 21 | } 22 | 23 | function close() { 24 | opacity = 0; 25 | focus = false; 26 | parent.focus = true; 27 | closed(); 28 | } 29 | 30 | Behavior on opacity { 31 | PropertyAnimation { 32 | duration: page.showDuration 33 | easing.type: Easing.InOutQuad; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /qml/Scrollable.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | 3 | ListView { 4 | id: view 5 | 6 | orientation: page.horizontal ? ListView.Horizontal : ListView.Vertical 7 | highlightResizeDuration: page.scrollDuration 8 | highlightMoveDuration: page.scrollDuration 9 | 10 | function scrollBy(value, xy, wh, moveHorizontally) { 11 | var err, h, v, size, indexAtFn; 12 | 13 | err = 4; 14 | if (moveHorizontally) { 15 | h = "contentX"; 16 | v = "contentY"; 17 | size = width; 18 | indexAtFn = indexAt; 19 | } else { 20 | h = "contentY"; 21 | v = "contentX"; 22 | size = height; 23 | indexAtFn = function(y, x) { return indexAt(x, y); }; 24 | } 25 | 26 | if (value < 0) { 27 | if (moveHorizontally !== page.horizontal) { 28 | view[h] = Math.max(view[h] + value, 0); 29 | } else if ( indexAtFn(view[h] - err, 0) !== currentIndex ) { 30 | previous(); 31 | view[v] = 0; 32 | if (currentItem[xy] < view[h]) { 33 | view[h] = currentItem[xy] + Math.max(0, currentItem[wh] - size); 34 | } 35 | } else if (moveHorizontally ? !atXBeginning : !atYBeginning) { 36 | view[h] += value; 37 | } 38 | } else if (value > 0) { 39 | if (moveHorizontally !== page.horizontal) { 40 | if (currentItem[xy] + currentItem[wh] > view[h] + size + err) 41 | view[h] = Math.min(view[h] + value, currentItem[xy] + currentItem[wh] - size); 42 | } else if ( indexAtFn(view[h] + size + err, 0) !== currentIndex ) { 43 | next(); 44 | view[v] = 0; 45 | if (currentItem[xy] + currentItem[wh] > view[h] + size) { 46 | view[h] = currentItem[xy] - Math.max(0, size - currentItem[wh]); 47 | } 48 | } else if (moveHorizontally ? !atXEnd : !atYEnd) { 49 | view[h] += value; 50 | } 51 | } 52 | } 53 | 54 | function scroll(x, y) { 55 | scrollBy(x, "x", "width", true); 56 | scrollBy(y, "y", "height", false); 57 | } 58 | 59 | function updateScroll() { 60 | var index = indexAt(contentX + width/2, contentY + height/2); 61 | if (index !== -1 && index !== currentIndex) { 62 | behaviorContextX.enabled = behaviorContextY.enabled = false; 63 | var x = contentX; 64 | var y = contentY; 65 | currentIndex = index; 66 | contentX = x; 67 | contentY = y; 68 | behaviorContextX.enabled = behaviorContextY.enabled = true; 69 | } 70 | } 71 | 72 | Behavior on contentX { 73 | id: behaviorContextX 74 | NumberAnimation { 75 | duration: page.scrollDuration 76 | easing.type: Easing.OutQuad; 77 | } 78 | } 79 | Behavior on contentY { 80 | id: behaviorContextY 81 | NumberAnimation { 82 | duration: page.scrollDuration 83 | easing.type: Easing.OutQuad; 84 | } 85 | } 86 | 87 | onFlickEnded: updateScroll() 88 | onMovementEnded: updateScroll() 89 | } 90 | -------------------------------------------------------------------------------- /qml/Storage.js: -------------------------------------------------------------------------------- 1 | function getDatabase(id) { 2 | return [id ? id + "-" : "", 3 | LocalStorage.openDatabaseSync("ImageQuick", "1.0", "StorageDatabase", 100000)]; 4 | } 5 | 6 | function initialize(db) { 7 | db[1].transaction( 8 | function(tx) { 9 | tx.executeSql('CREATE TABLE IF NOT EXISTS settings(setting TEXT UNIQUE, value TEXT)'); 10 | }); 11 | } 12 | 13 | function setSettings(db, settings) { 14 | var res, setting; 15 | res = false; 16 | db[1].transaction( 17 | function(tx) { 18 | for (setting in settings) { 19 | var rs = tx.executeSql( 20 | 'INSERT OR REPLACE INTO settings VALUES (?,?);', 21 | [db[0] + setting, settings[setting]]); 22 | res = rs.rowsAffected > 0; 23 | } 24 | }); 25 | return res; 26 | } 27 | 28 | function getSetting(db, setting) { 29 | var res; 30 | db[1].transaction( 31 | function(tx) { 32 | try { 33 | var rs = tx.executeSql('SELECT value FROM settings WHERE setting=?;', [db[0] + setting]); 34 | if (rs.rows.length > 0) { 35 | res = rs.rows.item(0).value; 36 | } 37 | } catch(err) { 38 | console.debug('Restoring failed: ' + err); 39 | } 40 | }) 41 | return res 42 | } 43 | -------------------------------------------------------------------------------- /qml/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.2 2 | import QtQuick.Window 2.1 3 | import QtQuick.LocalStorage 2.0 4 | import "Storage.js" as Storage 5 | 6 | Window { 7 | id: window 8 | visible: true 9 | width: 360 10 | height: 360 11 | visibility: page.fullscreen ? "FullScreen" : "Windowed" 12 | 13 | Rectangle { 14 | id: page 15 | anchors.fill: parent 16 | color: "black" 17 | focus: true 18 | 19 | property bool horizontal: false 20 | property string filter: "" 21 | property string single: filename 22 | property bool one: filename !== "" 23 | 24 | /* colors */ 25 | property color colorCurrent: "yellow" 26 | property color colorImage: "white" 27 | property color colorDirectory: "#9df" 28 | property color colorOther: "gray" 29 | 30 | /* animation properties */ 31 | property int scrollDuration: 100 32 | property int zoomDuration: 250 33 | property int showDuration: 300 34 | 35 | property int scrollAmount: 200 36 | 37 | property bool fullscreen: true 38 | 39 | property bool saved: false 40 | property bool restored: false 41 | property bool selfLoaded: false 42 | property bool loaded: selfLoaded && view.loaded 43 | 44 | property int lastWindowWidth: 0 45 | property int lastWindowHeight: 0 46 | property int lastWindowX: 0 47 | property int lastWindowY: 0 48 | 49 | function quit() { 50 | close(); 51 | Qt.quit(); 52 | } 53 | 54 | function restoreSession() { 55 | var path, val, db; 56 | 57 | if (restored || !loaded) 58 | return; 59 | restored = true; 60 | 61 | if (!session) { 62 | view.setSource(src); 63 | return; 64 | }; 65 | 66 | db = Storage.getDatabase(session); 67 | 68 | path = Storage.getSetting(db, "path"); 69 | view.setSource(src || path || currentPath); 70 | 71 | val = parseInt( Storage.getSetting(db, "current") ); 72 | if (val >= 0) 73 | view.select(val); 74 | 75 | val = Storage.getSetting(db, "horizontal"); 76 | if (val) 77 | horizontal = val !== "false" && val !== "0"; 78 | 79 | val = parseFloat(Storage.getSetting(db, "zoom")); 80 | if (val) 81 | view.zoom = val; 82 | 83 | val = Storage.getSetting(db, "filter"); 84 | if (val !== null) 85 | filter = val; 86 | 87 | val = Storage.getSetting(db, "state"); 88 | if (val !== undefined) 89 | view.state = val; 90 | 91 | val = Storage.getSetting(db, "one"); 92 | if (val) 93 | one = val === "true" || val === "1"; 94 | 95 | val = parseFloat(Storage.getSetting(db, "sharpen")); 96 | if (val) 97 | view.sharpenStrength = val; 98 | 99 | val = Storage.getSetting(db, "history"); 100 | if (val) 101 | view.setHistory(JSON.parse(val)); 102 | 103 | val = Storage.getSetting(db, "fullscreen"); 104 | if (val) 105 | fullscreen = val === "true" || val === "1"; 106 | 107 | val = parseInt( Storage.getSetting(db, "width") ); 108 | if (val > 0) 109 | lastWindowWidth = window.width = val; 110 | 111 | val = parseInt( Storage.getSetting(db, "height") ); 112 | if (val > 0) 113 | lastWindowHeight = window.height = val; 114 | 115 | val = parseInt( Storage.getSetting(db, "x") ); 116 | if (val >= 0) 117 | lastWindowX = window.x = val; 118 | 119 | val = parseInt( Storage.getSetting(db, "y") ); 120 | if (val >= 0) 121 | lastWindowY = window.y = val; 122 | } 123 | 124 | function saveSession() { 125 | var d, db; 126 | 127 | if (!session || saved || !restored) return; 128 | saved = true; 129 | 130 | d = { 131 | "current": view.current(), 132 | "path": view.source(), 133 | "last-access": new Date().toISOString(), 134 | "horizontal": horizontal, 135 | "state": view.state, 136 | "one": view.one, 137 | "zoom": view.zoom, 138 | "filter": filter, 139 | "sharpen": view.sharpenStrength, 140 | "history": JSON.stringify(view.getHistory()), 141 | "fullscreen": fullscreen, 142 | "width": fullscreen ? lastWindowWidth : window.width, 143 | "height": fullscreen ? lastWindowHeight : window.height, 144 | "x": fullscreen ? lastWindowX : window.x, 145 | "y": fullscreen ? lastWindowY : window.y, 146 | } 147 | 148 | db = Storage.getDatabase(session); 149 | Storage.initialize(db); 150 | Storage.setSettings(db, d); 151 | } 152 | 153 | function search() { 154 | searchEdit.show(); 155 | } 156 | 157 | function isMatched(fileName, filter) { 158 | return fileName.toLowerCase().indexOf(filter) !== -1; 159 | } 160 | 161 | function showHelp() { 162 | helpPopup.show(); 163 | } 164 | 165 | /* main view */ 166 | ImageView { 167 | id: view 168 | anchors.fill: parent 169 | property bool loaded: false 170 | Component.onCompleted: loaded = true 171 | Component.onDestruction: page.saveSession() 172 | } 173 | 174 | /* search box */ 175 | EditBox { 176 | id: searchEdit 177 | text: page.filter 178 | label: "Filter:" 179 | onChanged: { 180 | page.filter = text.toLowerCase(); 181 | } 182 | onAccepted: { 183 | page.filter = text.toLowerCase(); 184 | if (view.currentItem && view.currentItem.isHidden) { 185 | view.next(); 186 | if (view.currentItem.isHidden) 187 | view.previous(); 188 | } 189 | } 190 | onRejected: { 191 | page.filter = ""; 192 | } 193 | } 194 | 195 | /* url edit box */ 196 | EditBox { 197 | id: urlEdit 198 | label: "URL:" 199 | onAccepted: { 200 | view.goTo(text); 201 | } 202 | } 203 | 204 | /* search box */ 205 | Help { 206 | id: helpPopup 207 | } 208 | 209 | onLoadedChanged: if (loaded) restoreSession() 210 | Component.onCompleted: selfLoaded = true 211 | Component.onDestruction: saveSession() 212 | 213 | /* keyboard */ 214 | Keys.onBackPressed: { 215 | view.back(); 216 | event.accepted = true; 217 | } 218 | Keys.onAsteriskPressed: { 219 | view.zoom = 1.0; 220 | view.state = "NORMAL"; 221 | event.accepted = true; 222 | } 223 | Keys.onPressed: { 224 | var k, m, shift, ctrl; 225 | 226 | k = event.key; 227 | m = event.modifiers; 228 | shift = event.modifiers & Qt.ShiftModifier; 229 | ctrl = event.modifiers & Qt.ControlModifier; 230 | 231 | event.accepted = true; 232 | 233 | if (k === Qt.Key_A) { 234 | view.sharpenStrength = Math.min(1.0, view.sharpenStrength + 0.05); 235 | } else if (k === Qt.Key_Z) { 236 | view.sharpenStrength = Math.max(0.0, view.sharpenStrength - 0.05); 237 | } else if (ctrl && (k === Qt.Key_D || k === Qt.Key_L)) { 238 | urlEdit.text = view.currentItem ? view.currentItem.path(true) : ""; 239 | urlEdit.show(); 240 | } else if ( k === Qt.Key_Apostrophe || (ctrl && k === Qt.Key_F) ) { 241 | search(); 242 | } else if ( k === Qt.Key_F ) { 243 | if (!fullscreen) { 244 | lastWindowWidth = window.width; 245 | lastWindowHeight = window.height; 246 | lastWindowX = window.x; 247 | lastWindowY = window.y; 248 | } 249 | fullscreen = !fullscreen; 250 | } else if (k === Qt.Key_H) { 251 | view.zoom = 1.0; 252 | view.state = "FIT-TO-HEIGHT"; 253 | } else if ( (shift && k === Qt.Key_N) || k === Qt.Key_K || k === Qt.Key_B ) { 254 | view.previous() 255 | } else if (k === Qt.Key_J || k === Qt.Key_N) { 256 | view.next() 257 | } else if (k === Qt.Key_O) { 258 | horizontal = !horizontal 259 | } else if (k === Qt.Key_Q || k === Qt.Key_Escape) { 260 | quit(); 261 | } else if ( (ctrl && k === Qt.Key_R) || k === Qt.Key_F5 ) { 262 | view.reload(); 263 | } else if (k === Qt.Key_W) { 264 | view.zoom = 1.0; 265 | view.state = "FIT-TO-WIDTH"; 266 | } else if (k === Qt.Key_Enter || k === Qt.Key_Return) { 267 | view.forward() 268 | } else if (k === Qt.Key_Right) { 269 | view.scroll(scrollAmount, 0) 270 | } else if (k === Qt.Key_Left) { 271 | view.scroll(-scrollAmount, 0) 272 | } else if (k === Qt.Key_Up) { 273 | view.scroll(0, -scrollAmount) 274 | } else if (k === Qt.Key_Down) { 275 | view.scroll(0, scrollAmount) 276 | } else if (k === Qt.Key_Home) { 277 | view.select(0); 278 | view.positionViewAtBeginning() 279 | } else if (k === Qt.Key_End) { 280 | view.select(view.count-1); 281 | view.positionViewAtEnd() 282 | } else if (k === Qt.Key_PageDown) { 283 | view.scroll(0, view.height-scrollAmount) 284 | } else if (k === Qt.Key_PageUp) { 285 | view.scroll(0, -view.height+scrollAmount) 286 | } else if (k === Qt.Key_Space) { 287 | if (horizontal) 288 | view.scroll( (shift ? -1 : 1) * (view.width-100), 0 ) 289 | else 290 | view.scroll( 0, (shift ? -1 : 1) * (view.height-100) ) 291 | } else if (k === Qt.Key_Plus) { 292 | view.zoom += 0.125; 293 | } else if (k === Qt.Key_Minus) { 294 | view.zoom -= 0.125; 295 | } else if (k === Qt.Key_Period) { 296 | view.zoom = 1.0; 297 | view.state = "FILL"; 298 | } else if (k === Qt.Key_Slash) { 299 | view.zoom = 1.0; 300 | view.state = "FIT"; 301 | } else if (k === Qt.Key_Backspace) { 302 | view.back(); 303 | } else if (k === Qt.Key_Question || k === Qt.Key_F1) { 304 | showHelp(); 305 | } else { 306 | event.accepted = false; 307 | } 308 | } 309 | } 310 | } 311 | -------------------------------------------------------------------------------- /resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qml/ImageItem.qml 4 | qml/ImageLabel.qml 5 | qml/ImageView.qml 6 | qml/main.qml 7 | qml/Scrollable.qml 8 | qml/History.js 9 | qml/Storage.js 10 | qml/Picture.qml 11 | qml/EditBox.qml 12 | qml/Osd.qml 13 | qml/Help.qml 14 | qml/HelpItem.qml 15 | qml/Popup.qml 16 | 17 | 18 | images/imagequick.svg 19 | 20 | 21 | --------------------------------------------------------------------------------