245 lines
8.6 KiB
C++
245 lines
8.6 KiB
C++
#include "headeractivity.h"
|
|
#include "quickhelper.h"
|
|
#include "qdebug.h"
|
|
#include <QQuickItem>
|
|
#include "FigmaStyles.h"
|
|
#include "callbackwrapper.h"
|
|
#include "ArrDifferentTypes.h"
|
|
#include <QQuickWindow>
|
|
|
|
HeaderActivity::HeaderActivity(QQuickItem * item, QObject *parent)
|
|
: QObject{parent}, root(item)
|
|
{
|
|
if (!item) {
|
|
return;
|
|
}
|
|
|
|
init();
|
|
}
|
|
|
|
void HeaderActivity::pageChanged()
|
|
{
|
|
|
|
}
|
|
|
|
void HeaderActivity::isAllowChangePage(const std::function<void ()> &continueChange, const std::function<void ()> &blockChange)
|
|
{
|
|
continueChange();
|
|
}
|
|
|
|
void HeaderActivity::setTitle(const QString &name)
|
|
{
|
|
if(fieldLabelTitle == 0) return;
|
|
|
|
fieldLabelTitle->setProperty("text", name);
|
|
}
|
|
|
|
void HeaderActivity::init()
|
|
{
|
|
QString name = root->objectName();
|
|
if (!isAlllElementFound()) return;
|
|
|
|
addMouseAreaToElementsToNavigation();
|
|
}
|
|
|
|
void HeaderActivity::addMouseAreaToElementsToNavigation(){
|
|
|
|
QuickHelper::addMouseAreaElements(fieldHideWindow,
|
|
[this] {
|
|
emit hideWindowClick();
|
|
},
|
|
[this]{
|
|
if (fieldHideWindow->isEnabled()) {
|
|
fieldHideWindow->setProperty("color", QML::CORLOR_MENU_ITEM_SELECTED);
|
|
}
|
|
},
|
|
[this]{
|
|
if (fieldHideWindow->isEnabled()) {
|
|
fieldHideWindow->setProperty("color", QML::CORLOR_MENU_ITEM_BASE_Header);
|
|
}
|
|
});
|
|
|
|
QuickHelper::addMouseAreaElements(fieldCreateProject,
|
|
[this] {
|
|
emit newProjectItemClick();
|
|
},
|
|
[this]{
|
|
if (fieldCreateProject->isEnabled()) {
|
|
fieldCreateProject->setProperty("color", QML::CORLOR_MENU_ITEM_SELECTED);
|
|
}
|
|
},
|
|
[this]{
|
|
if (fieldCreateProject->isEnabled()) {
|
|
fieldCreateProject->setProperty("color", QML::CORLOR_MENU_ITEM_BASE_Header);
|
|
}
|
|
});
|
|
|
|
QuickHelper::addMouseAreaElements(fieldProjects,
|
|
[this] {
|
|
emit projectItemClick();
|
|
},
|
|
[this]{
|
|
if (fieldProjects->isEnabled()) {
|
|
fieldProjects->setProperty("color", QML::CORLOR_MENU_ITEM_SELECTED);
|
|
}
|
|
},
|
|
[this]{
|
|
if (fieldProjects->isEnabled()) {
|
|
fieldProjects->setProperty("color", QML::CORLOR_MENU_ITEM_BASE_Header);
|
|
}
|
|
});
|
|
|
|
QuickHelper::addMouseAreaElements(fieldHome,
|
|
[this] {
|
|
emit homeClick();
|
|
},
|
|
[this]{
|
|
if (fieldHome->isEnabled()) {
|
|
fieldHome->setProperty("color", QML::CORLOR_MENU_ITEM_SELECTED);
|
|
}
|
|
},
|
|
[this]{
|
|
if (fieldHome->isEnabled()) {
|
|
fieldHome->setProperty("color", QML::CORLOR_MENU_ITEM_BASE_Header);
|
|
}
|
|
});
|
|
|
|
QuickHelper::addMouseAreaElements(fieldCloseWindow,
|
|
[this] {
|
|
emit closeWindowClick();
|
|
},
|
|
[this] {
|
|
if (fieldCloseWindow->isEnabled()) {
|
|
fieldCloseWindow->setProperty("color", QML::CORLOR_MENU_ITEM_SELECTED_EXIT);
|
|
}
|
|
},
|
|
[this] {
|
|
if (fieldCloseWindow->isEnabled()) {
|
|
fieldCloseWindow->setProperty("color", QML::CORLOR_MENU_ITEM_BASE_Header);
|
|
}
|
|
});
|
|
|
|
QString addComponent = QString::fromLocal8Bit(R"(
|
|
import QtQuick
|
|
import QtQuick.Controls
|
|
|
|
MouseArea {
|
|
id: root
|
|
anchors.fill: parent
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
property point clickPos: "0,0"
|
|
|
|
onPressed: function(mouse) {
|
|
if (mouse.button === Qt.LeftButton) {
|
|
clickPos = Qt.point(mouse.x, mouse.y)
|
|
} else if (mouse.button === Qt.RightButton) {
|
|
contextMenu.popup()
|
|
}
|
|
}
|
|
|
|
onPositionChanged: function(mouse) {
|
|
if (pressedButtons & Qt.LeftButton) {
|
|
|
|
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
|
|
quickUpdaterData.arrDifferentTypes[0] = delta
|
|
quickUpdaterData.arrDifferentTypes[1].invoke()
|
|
}
|
|
}
|
|
|
|
Menu {
|
|
id: contextMenu
|
|
|
|
MenuItem {
|
|
text: "Скрыть"
|
|
onTriggered: {
|
|
quickUpdaterData.arrDifferentTypes[2].invoke()
|
|
}
|
|
}
|
|
|
|
MenuItem {
|
|
text: "Закрыть"
|
|
onTriggered: {
|
|
quickUpdaterData.arrDifferentTypes[3].invoke()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
)");
|
|
|
|
QVariantList list;
|
|
list.append(QVariant::fromValue(QPoint()));
|
|
auto wrapperMove = new CallbackWrapper([this] {handleWrapperMove();});
|
|
auto wrapperHide = new CallbackWrapper([this] {handleWrapperHide();});
|
|
auto wrapperClose = new CallbackWrapper([this] {handleWrapperClose();});
|
|
|
|
list.append(QVariant::fromValue(wrapperMove));
|
|
list.append(QVariant::fromValue(wrapperHide));
|
|
list.append(QVariant::fromValue(wrapperClose));
|
|
|
|
QObject *customTitleMouseArea = 0;
|
|
headerArrDifferentTypes = 0;
|
|
QuickHelper::addComponent(fieldLabelTitle, list, addComponent, &customTitleMouseArea, &headerArrDifferentTypes);
|
|
}
|
|
|
|
void HeaderActivity::handleWrapperMove()
|
|
{
|
|
auto listVariant = headerArrDifferentTypes->getArrDifferentTypes();
|
|
QPoint offset = listVariant[0].toPoint();
|
|
auto window = root->window();
|
|
auto windowPos = window->position();
|
|
window->setPosition(windowPos + offset);
|
|
}
|
|
|
|
void HeaderActivity::handleWrapperHide()
|
|
{
|
|
emit hideWindowClick();
|
|
}
|
|
|
|
void HeaderActivity::handleWrapperClose()
|
|
{
|
|
emit closeWindowClick();
|
|
}
|
|
|
|
bool HeaderActivity::isAlllElementFound()
|
|
{
|
|
bool retCode = true;
|
|
fieldHideWindow = QuickHelper::getQuickItem(root, FIELD_HIDE_WINDOW);
|
|
if (!fieldHideWindow) {
|
|
qWarning() << "Failed to get fieldHideWindow:" << FIELD_HIDE_WINDOW;
|
|
retCode = false;
|
|
}
|
|
|
|
fieldCloseWindow = QuickHelper::getQuickItem(root, FIELD_CLOSE_WINDOW);
|
|
if (!fieldCloseWindow) {
|
|
qWarning() << "Failed to get fieldCloseWindow:" << FIELD_CLOSE_WINDOW;
|
|
retCode = false;
|
|
}
|
|
|
|
fieldCreateProject = QuickHelper::getQuickItem(root, FIELD_CREATE_PROJECT);
|
|
if (!fieldCreateProject) {
|
|
qWarning() << "Failed to get fieldCreateProject:" << FIELD_CREATE_PROJECT;
|
|
retCode = false;
|
|
}
|
|
|
|
fieldProjects = QuickHelper::getQuickItem(root, FIELD_PROJECTS);
|
|
if (!fieldProjects) {
|
|
qWarning() << "Failed to get fieldProjects:" << FIELD_PROJECTS;
|
|
retCode = false;
|
|
}
|
|
|
|
fieldHome = QuickHelper::getQuickItem(root, FIELD_HOME);
|
|
if (!fieldHome) {
|
|
qWarning() << "Failed to get fieldHome:" << FIELD_HOME;
|
|
retCode = false;
|
|
}
|
|
|
|
fieldLabelTitle = QuickHelper::getQuickItem(root, FIELD_LABEL_TITLE);
|
|
if (!fieldLabelTitle) {
|
|
qWarning() << "Failed to get fieldLabelTitle:" << FIELD_LABEL_TITLE;
|
|
retCode = false;
|
|
}
|
|
|
|
return retCode;
|
|
}
|