Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions qml/FileOpenWindow.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5

import space.developers 1.0

ApplicationWindow {
id: openImageWindow
signal signalExit
minimumWidth: 300
minimumHeight: 300
width: 400
height: 400
visible: true

Rectangle {
width: parent.width
height: parent.height - anotherWindow_button.height
color: "gray"

WorkWithFiles {
anchors.top: parent.top
anchors.topMargin: 15
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width
height: parent.height
}
}

Button {
id: anotherWindow_button
text: qsTr("Главное окно")
width: 180
height: 50
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
openImageWindow.close()
}
}
}
12 changes: 11 additions & 1 deletion qml/NewTable.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import QtQuick 2.0
import QtQuick.Controls 1.0

import space.developers 1.0

Rectangle {
id:colorRecta
color: "#F0F8FF" // crimson
Expand All @@ -22,7 +24,15 @@ Rectangle {
dataModel.updateData(model.path)
}
else {
workFile.openFile(model.path,model.flag)
if (model.flag === "jpg" || model.flag === "png" || model.flag === "jpeg") {
workWithFiles.openImage(model.path)
var component = Qt.createComponent("FileOpenWindow.qml")
var window = component.createObject("root")
window.show()
}
else {
workWithFiles.openFile(model.path)
}
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ Window {
id: dataModel
}

WorkFile {
id: workFile
WorkWithFiles {
id: workWithFiles
}

}

1 change: 1 addition & 0 deletions qml/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<file>ColumnFlag.qml</file>
<file>PathMenu.qml</file>
<file>MasterButton.qml</file>
<file>FileOpenWindow.qml</file>
</qresource>
<qresource prefix="/imeg">
<file alias="back">imeg/back-icon.png</file>
Expand Down
34 changes: 31 additions & 3 deletions src/executionfile.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
#include "executionfile.h"
#include <QQuickView>
#include <QDesktopServices>

ExecutionFile::ExecutionFile(QObject *parent): QObject (parent)
ExecutionFile::ExecutionFile(QQuickItem *parent): QQuickPaintedItem(parent)
{

}

void ExecutionFile::openFile(QString path, QString flag)
void ExecutionFile::paint(QPainter *painter)
{
m_fale=path+flag;
qDebug() << "paint" << m_filePath;
QPixmap pixmap("C:/Users/User/Desktop/img.jpg");
QRectF source(0, 0, 0, 0);
QRectF imageRect = boundingRect();
imageRect.setSize(pixmap.size().scaled(boundingRect().size().toSize(),Qt::KeepAspectRatio));
imageRect.moveCenter(boundingRect().center());
painter->drawPixmap(imageRect, pixmap, source);
}

void ExecutionFile::openFile(const QString &path)
{
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}

void ExecutionFile::filePath(const QString &path)
{
if (m_filePath == path)
return;
m_filePath = path;
update();
}

void ExecutionFile::openImage(const QString &path)
{
filePath(path);
qDebug() << "m_filePath =" << m_filePath;
QQuickPaintedItem::update();
}
16 changes: 11 additions & 5 deletions src/executionfile.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#ifndef EXECUTIONFILE_H
#define EXECUTIONFILE_H
#include <QObject>
#include <QPainter>
#include <QQuickPaintedItem>

class ExecutionFile : public QObject
class ExecutionFile : public QQuickPaintedItem
{
Q_OBJECT
public:
ExecutionFile(QObject *parent = nullptr);
Q_INVOKABLE void openFile(QString path,QString flag);
ExecutionFile(QQuickItem *parent = nullptr);

void paint(QPainter *painter) override;

Q_INVOKABLE void openFile(const QString &path);
Q_INVOKABLE void filePath(const QString &path);
Q_INVOKABLE void openImage(const QString &path);

private:
QString m_fale;
QString m_filePath;
};

#endif // EXECUTIONFILE_H
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);

qmlRegisterType<FilesList>("space.developers", 1, 0, "NewTable");
qmlRegisterType<ExecutionFile>("space.developers", 1, 0, "WorkFile");
qmlRegisterType<ExecutionFile>("space.developers", 1, 0, "WorkWithFiles");


QQmlApplicationEngine engine;


const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
Expand Down