#include "projectpageactivity.h" #include #include #include #include "QQuickItem" #include "cycleupdater.h" #include "quickhelper.h" #include #include "dynamicloader.h" #include #include #include "settingsrepository.h" #include "callbackwrapper.h" #include "ArrDifferentTypes.h" #include "recentfilesmodel.h" #include "FigmaStyles.h" #include "listfilesfiltermodel.h" #include "ArrDifferentTypes.h" #include "models/PasportModel.h" #include "views/projectstatusfragment.h" ProjectPageActivity::ProjectPageActivity(QQuickItem *item, QObject *parent) : root(item), QObject(parent) { if (!item) { qWarning() << "[C++] Root object is null"; return; } init(); } void ProjectPageActivity::pageChanged() { } void ProjectPageActivity::setProjectFolders(QStringList &listFiles) { if (!sourceModel) return; QVector newModelData; RecentFileItem temp; for(const auto& itemStr : listFiles) { temp.name = itemStr; newModelData.append(temp); } sourceModel->setItems(newModelData); } bool ProjectPageActivity::isAllElementsFound() { bool retCode = true; fieldSearchComponent = QuickHelper::getQuickItem(root, FIELD_SEARCH_COMPONENT); if (!fieldSearchComponent) { qWarning() << "Failed to get fieldSearchComponent:" << FIELD_SEARCH_COMPONENT; retCode = false; } fieldContentResultsOfSearch = QuickHelper::getQuickItem(root, FIELD_CONTENT_RESULTS_OF_SEARCH); if (!fieldContentResultsOfSearch) { qWarning() << "Failed to get fieldContentResultsOfSearch:" << FIELD_CONTENT_RESULTS_OF_SEARCH; retCode = false; } fieldLabelAvailibleSizeButton = QuickHelper::getQuickItem(root, FIELD_LABEL_AVAILIBLE_SIZE_BUTTON); if (!fieldLabelAvailibleSizeButton) { qWarning() << "Failed to get fieldLabelAvailibleSizeButton:" << FIELD_LABEL_AVAILIBLE_SIZE_BUTTON; retCode = false; } fieldAvailibleSizeProgressBar = QuickHelper::getQuickItem(root, FIELD_AVAILIBLE_SIZE_PROGRESS_BAR); if (!fieldAvailibleSizeProgressBar) { qWarning() << "Failed to get fieldAvailibleSizeProgressBar:" << FIELD_AVAILIBLE_SIZE_PROGRESS_BAR; retCode = false; } fieldAvailibleSizePassedBar = QuickHelper::getQuickItem(root, FIELD_AVAILIBLE_SIZE_PASSED_BAR); if (!fieldAvailibleSizePassedBar) { qWarning() << "Failed to get fieldAvailibleSizePassedBar:" << FIELD_AVAILIBLE_SIZE_PASSED_BAR; retCode = false; } fieldLabelProjectName = QuickHelper::getQuickItem(root, FIELD_LABEL_PROJECT_NAME); if (!fieldLabelProjectName) { qWarning() << "Failed to get fieldLabelProjectName:" << FIELD_LABEL_PROJECT_NAME; retCode = false; } fieldLabelProjectPath = QuickHelper::getQuickItem(root, FIELD_LABEL_PROJECT_PATH); if (!fieldLabelProjectPath) { qWarning() << "Failed to get fieldLabelProjectPath:" << FIELD_LABEL_PROJECT_PATH; retCode = false; } fieldShowProjectButton = QuickHelper::getQuickItem(root, FIELD_SHOW_PROJECT_BUTTON); if (!fieldShowProjectButton) { qWarning() << "Failed to get fieldShowProjectButton:" << FIELD_SHOW_PROJECT_BUTTON; retCode = false; } fieldDeleteProjectButton = QuickHelper::getQuickItem(root, FIELD_DELETE_PROJECT_BUTTON); if (!fieldDeleteProjectButton) { qWarning() << "Failed to get fieldDeleteProjectButton:" << FIELD_DELETE_PROJECT_BUTTON; retCode = false; } fieldPasport = QuickHelper::getQuickItem(root, FIELD_PASPORT); if (!fieldPasport) { qWarning() << "Failed to get fieldPasport:" << FIELD_PASPORT; retCode = false; } return retCode; } void ProjectPageActivity::init() { if (!isAllElementsFound()) return; hidePasport(); sourceModel = new ListFilesModel(this); filterModel = new ListFilesFilterModel(this); filterModel->setSourceModel(sourceModel); filterModel->setFilterExtension(""); connect(sourceModel, &ListFilesModel::allDataChanged, filterModel, &ListFilesFilterModel::allDataChangedHandler); loadAllFiles(); loadFolderStorage(); loadFilterComponent(); loadPasportFragment(); } void ProjectPageActivity::loadPasportFragment() { pasportFragment = new ProjectStatusFragment(fieldPasport,this); connect(pasportFragment, &ProjectStatusFragment::showProject, this, &ProjectPageActivity::showProjectHandler); connect(pasportFragment, &ProjectStatusFragment::deleteProject, this, &ProjectPageActivity::deleteProjectHandler); connect(pasportFragment, &ProjectStatusFragment::copyToClipBoardSignal, this, &ProjectPageActivity::copyToClipBoardSignalHandler); } void ProjectPageActivity::copyToClipBoardSignalHandler(QString text) { emit copyToClipBoardSignal(text); } void ProjectPageActivity::showProjectHandler(QString absolutePath) { emit showProject(absolutePath); } void ProjectPageActivity::deleteProjectHandler(QString absolutePath) { QString headerText="Подтверждение удаления"; QString contentText="Вы точно хотите удалить проект?"; auto actionOnAccept = [this, absolutePath]{ hidePasport(); emit deleteProject(absolutePath); emit afterDeleteProject(); }; auto actionOnDeny = []{}; emit setTextReplaceProject(headerText,contentText); emit showDialogReplaceProject(actionOnAccept, actionOnDeny); } void ProjectPageActivity::loadFilterComponent() { // QuickHelper::addContentToItem(fieldSearchComponent, FIGMA_SerchItem); QString textComponent = R"( import QtQuckApp SearchComponent { id: rootObject objectName: "SearchComponent" onTextChanged: function(text) { quickUpdaterData.arrDifferentTypes[1] = text quickUpdaterData.arrDifferentTypes[0].invoke() } } )"; QVariantList list; QObject* addedComponent = 0; CallbackWrapper * wrapper = new CallbackWrapper([this]{searchTextChanged();},fieldSearchComponent); list.append(QVariant::fromValue(wrapper)); QuickHelper::addComponent(fieldSearchComponent, list, textComponent,&addedComponent,&searchContextData); searchElement = qobject_cast(addedComponent); } void ProjectPageActivity::searchTextChanged() { auto data = searchContextData->getArrDifferentTypes(); QString text = data[1].toString(); filterModel->setFilterExtension(text); hidePasport(); } void ProjectPageActivity::loadAllFiles() { QString textComponent = R"( import QtQuckApp ListRecentFiles{ id: rootObject objectName: "ListRecentFiles" currentModel: quickUpdaterData.arrDifferentTypes[2] onItemSelected: function(text){ quickUpdaterData.arrDifferentTypes[4] = text; quickUpdaterData.arrDifferentTypes[3].invoke(); } } )"; QVariantList listItems; listItems.append(QVariant::fromValue(QML::COLOR_RECENT_ITEM_SELECTED)); listItems.append(QVariant::fromValue(QML::COLOR_RECENT_ITEM_BASE)); // ListFilesModel *model = new ListFilesModel(this); // listItems.append(QVariant::fromValue(model)); listItems.append(QVariant::fromValue(filterModel)); CallbackWrapper *clickWrapper = new CallbackWrapper([this]{projectListItemClick();},fieldContentResultsOfSearch); listItems.append(QVariant::fromValue(clickWrapper)); QObject *addedComponent = 0; QQuickItem *addedComponentItem = 0; QuickHelper::addComponent(fieldContentResultsOfSearch,listItems,textComponent,&addedComponent, &listViewModel); } void ProjectPageActivity::projectListItemClick() { auto data = listViewModel->getArrDifferentTypes(); QString text = data[4].toString(); if (text != "") { emit fileClick(text); } } void ProjectPageActivity::setCycleUpdate(CycleUpdater * cycle) { cycleUpdate = cycle; connect(cycleUpdate, &CycleUpdater::updateStorageInfo ,this, &ProjectPageActivity::updateStorageInfo); cycleUpdate->doEmitHandler(); } void ProjectPageActivity::updateStorageInfo(double freeBytes, double totalBytes) { QString numberFormat = QString::number(freeBytes / (1024.0 * 1024.0 * 1024.0), 'f', 2); if (fieldLabelAvailibleSizeButton) { fieldLabelAvailibleSizeButton->setProperty("text", numberFormat + " Гб"); } if (progressBarController) { double percent = 1.0 *freeBytes / totalBytes; percent = 1 - percent; percent*=100; QMetaObject::invokeMethod(progressBarController, "setPercent", Q_ARG(QVariant,percent )); } } inline void ProjectPageActivity::hidePasport() { if(fieldPasport) fieldPasport->setVisible(false); } inline void ProjectPageActivity::showPasport() { if(fieldPasport) fieldPasport->setVisible(true); } void ProjectPageActivity::updatePasport(const PasportModel&model) { fieldLabelProjectName->setProperty("text", model.getName()); fieldLabelProjectPath->setProperty("text", model.getPath()); showPasport(); } void ProjectPageActivity::loadFolderStorage() { if (fieldAvailibleSizeProgressBar && fieldAvailibleSizePassedBar){ progressBarController = QuickHelper::addProgressBar(fieldAvailibleSizeProgressBar,fieldAvailibleSizeProgressBar,fieldAvailibleSizePassedBar); } } void ProjectPageActivity::fileClickHandler() { auto value = projectModel->getArrDifferentTypes(); emit fileClick(value[2].toString()); } void ProjectPageActivity::isAllowChangePage(const std::function &continueChange, const std::function &blockChange) { continueChange(); }