2024-02-14 05:27:15 +00:00
|
|
|
#include "present_container.h"
|
2023-03-17 13:58:38 +00:00
|
|
|
#include "DocsManager.h"
|
2023-08-27 14:09:46 +00:00
|
|
|
#include "welcomepanel.h"
|
2023-03-17 13:58:38 +00:00
|
|
|
|
2023-08-29 03:52:56 +00:00
|
|
|
#include <QApplication>
|
2023-08-27 14:09:46 +00:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QGridLayout>
|
2023-03-17 13:58:38 +00:00
|
|
|
#include <QMenu>
|
2023-08-27 14:09:46 +00:00
|
|
|
#include <QPushButton>
|
2023-03-17 13:58:38 +00:00
|
|
|
|
|
|
|
using namespace Components;
|
|
|
|
using namespace Core;
|
2023-08-29 04:18:41 +00:00
|
|
|
using namespace Presents;
|
2023-03-17 13:58:38 +00:00
|
|
|
|
2024-02-14 05:27:15 +00:00
|
|
|
PresentContainer::PresentContainer(QWidget *ptr)
|
|
|
|
: QWidget(ptr),
|
2023-08-27 14:09:46 +00:00
|
|
|
title_store(new QComboBox(this)),
|
|
|
|
stack_container(new QStackedWidget(this)),
|
|
|
|
welcome_list(new WelcomePanel(this)),
|
|
|
|
close_btn(new QPushButton("X", this)) {
|
|
|
|
auto layout = new QGridLayout(this);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
layout->setMargin(0);
|
2023-03-17 13:58:38 +00:00
|
|
|
|
2023-08-27 14:09:46 +00:00
|
|
|
layout->addWidget(title_store, 0, 0, 1, 3);
|
|
|
|
layout->addWidget(close_btn, 0, 3);
|
|
|
|
close_btn->setMaximumSize(QSize(30, 30));
|
2023-09-04 14:35:14 +00:00
|
|
|
close_btn->setEnabled(false);
|
2023-08-27 14:09:46 +00:00
|
|
|
|
|
|
|
items_store << welcome_list;
|
|
|
|
stack_container->addWidget(welcome_list->widget());
|
2023-09-04 14:35:14 +00:00
|
|
|
layout->addWidget(stack_container, 1, 0, 1, 4);
|
2023-08-27 14:09:46 +00:00
|
|
|
title_store->addItem(welcome_list->name());
|
|
|
|
|
|
|
|
layout->setRowStretch(0, 0);
|
|
|
|
layout->setRowStretch(1, 1);
|
|
|
|
layout->setColumnStretch(0, 1);
|
|
|
|
layout->setColumnStretch(1, 1);
|
|
|
|
layout->setColumnStretch(2, 1);
|
|
|
|
layout->setColumnStretch(3, 0);
|
|
|
|
|
2024-02-14 05:27:15 +00:00
|
|
|
connect(title_store, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &PresentContainer::change_view);
|
|
|
|
connect(close_btn, &QPushButton::toggled, this, &PresentContainer::close_current_view);
|
|
|
|
|
|
|
|
connect(stack_container, &QStackedWidget::currentChanged, [this](int idx){
|
|
|
|
if(idx >= 0){
|
|
|
|
auto inst = items_store.at(idx);
|
|
|
|
for(auto &l : listeners_store)
|
|
|
|
l->currentChanged(inst);
|
|
|
|
}
|
|
|
|
});
|
2023-03-17 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 05:27:15 +00:00
|
|
|
QWidget *PresentContainer::hostWidget() const { return (QWidget *)this; }
|
2023-03-17 13:58:38 +00:00
|
|
|
|
2023-08-27 14:09:46 +00:00
|
|
|
#include <libConfig.h>
|
|
|
|
using namespace Config;
|
|
|
|
|
2024-02-14 05:27:15 +00:00
|
|
|
void PresentContainer::append(FilePresent *ins) {
|
2023-08-27 14:09:46 +00:00
|
|
|
if (!items_store.contains(ins)) {
|
2023-08-15 14:40:40 +00:00
|
|
|
items_store.append(ins);
|
2023-08-27 14:09:46 +00:00
|
|
|
title_store->addItem(ins->name());
|
2023-09-04 14:35:14 +00:00
|
|
|
ins->widget()->setParent(nullptr);
|
2023-08-27 14:09:46 +00:00
|
|
|
stack_container->addWidget(ins->widget());
|
|
|
|
|
2023-09-04 14:35:14 +00:00
|
|
|
active(ins);
|
|
|
|
} else
|
|
|
|
throw new SimpleException<bool>("非法操作", "重复添加视图:" + ins->name());
|
2023-03-17 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
2023-09-04 14:35:14 +00:00
|
|
|
#include <QDebug>
|
2024-02-14 05:27:15 +00:00
|
|
|
bool PresentContainer::active(const FilePresent *ins) {
|
2023-08-15 14:40:40 +00:00
|
|
|
if (!items_store.contains(ins))
|
2023-03-17 13:58:38 +00:00
|
|
|
return false;
|
|
|
|
|
2023-08-27 14:09:46 +00:00
|
|
|
auto index = items_store.indexOf(ins);
|
|
|
|
title_store->setCurrentIndex(index);
|
|
|
|
title_store->setItemText(index, ins->name());
|
|
|
|
stack_container->setCurrentIndex(index);
|
2023-03-17 13:58:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-02-14 05:27:15 +00:00
|
|
|
void PresentContainer::remove(const FilePresent *ins) {
|
2023-08-15 14:40:40 +00:00
|
|
|
if (!items_store.contains(ins))
|
|
|
|
return;
|
2023-03-17 13:58:38 +00:00
|
|
|
|
2023-08-27 14:09:46 +00:00
|
|
|
auto index = items_store.indexOf(ins);
|
|
|
|
items_store.removeAt(index);
|
|
|
|
title_store->removeItem(index);
|
|
|
|
stack_container->removeWidget(ins->widget());
|
2023-03-17 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 05:27:15 +00:00
|
|
|
bool PresentContainer::contains(const FilePresent *ins) const {
|
2023-03-17 13:58:38 +00:00
|
|
|
for (auto &insit : items_store) {
|
|
|
|
if (insit == ins)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-02-14 05:27:15 +00:00
|
|
|
bool PresentContainer::avaliable(FilePresent *vins) {
|
2023-09-04 14:35:14 +00:00
|
|
|
auto global_test = QApplication::activeWindow();
|
|
|
|
if (!global_test)
|
2023-08-29 03:52:56 +00:00
|
|
|
return true;
|
2023-09-04 14:35:14 +00:00
|
|
|
return this->isActiveWindow();
|
2023-08-29 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 05:27:15 +00:00
|
|
|
void PresentContainer::change_view(int view_index) {
|
2023-08-27 14:09:46 +00:00
|
|
|
auto view_inst = items_store[view_index];
|
|
|
|
active(view_inst);
|
|
|
|
|
|
|
|
close_btn->setEnabled(view_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
2024-02-14 05:27:15 +00:00
|
|
|
void PresentContainer::close_current_view() {
|
2023-08-27 14:09:46 +00:00
|
|
|
auto index = title_store->currentIndex();
|
2023-08-29 03:52:56 +00:00
|
|
|
const_cast<FilePresent *>(items_store[index])->beforeClose();
|
2023-03-17 13:58:38 +00:00
|
|
|
}
|