代码拉取完成,页面将自动刷新
同步操作将从 Vanishi/DS 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "tab.h"
#include "Index/Index.h"
#include "Index/Settings.h"
#include "Index/About.h"
#include "Task/Task.h"
#include "Task/TaskManage.h"
#include "Task/TaskData.h"
#include "Utils/models.h"
#include "Utils/database.h"
#include <QLabel>
#include <QTabBar>
#include <QMenu>
#include <QDebug>
Tab::Tab(QWidget *parent) : QTabWidget(parent)
{
QString stylesheet_QTabBar = "QTabWidget::pane{} \
QTabBar::tab {color:rgb(0,0,0);font-family:Microsoft YaHei;font-size:13px;min-width:110px;height:30px;padding:0px 5px;border-radius:4px;margin-left:6px;margin-top:4px;margin-bottom:2px;} \
QTabBar::tab:!selected {background:rgb(255,255,255);border:1px solid rgb(233,233,233);} \
QTabBar::tab:hover{background:rgba(255,255,255,0.8);} \
QTabBar::tab:selected {background:rgb(219,228,241);}";
setStyleSheet(stylesheet_QTabBar);
QTabBar *tabBar = this->tabBar();
tabBar->setTabsClosable(true);
tabBar->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
tabBar->setMovable(true);
tabBar->setContextMenuPolicy(Qt::CustomContextMenu);
// connect(tabBar, &QTabBar::customContextMenuRequested, this, &Tab::onHandleContextMenuRequested);
connect(tabBar, &QTabBar::tabCloseRequested, this, &Tab::onCloseTab);
setDocumentMode(true);
// setElideMode(Qt::ElideRight);
}
void Tab::createIndex(){
bool create = true;
for (int i = 0; i < this->count(); ++i) {
if("Index"==QString(this->widget(i)->metaObject()->className())){
create = false;
this->setCurrentIndex(i);
break;
}
}
if(create){
Index *page = new Index(this);
addTab(page,formatTabName("首页"));
setCurrentWidget(page);
connect(page,&Index::notifyCreateTask,this,[this](const QString address){
createTask(address);
});
}
}
void Tab::createSettings(){
bool create = true;
for (int i = 0; i < this->count(); ++i) {
if("Settings"==QString(this->widget(i)->metaObject()->className())){
create = false;
this->setCurrentIndex(i);
break;
}
}
if(create){
Settings *page = new Settings(this);
addTab(page,formatTabName("设置"));
setCurrentWidget(page);
}
}
void Tab::createAbout(){
bool create = true;
for (int i = 0; i < this->count(); ++i) {
if("About"==QString(this->widget(i)->metaObject()->className())){
create = false;
this->setCurrentIndex(i);
break;
}
}
if(create){
About *page = new About(this);
addTab(page,formatTabName("关于"));
setCurrentWidget(page);
}
}
void Tab::createTask(const QString address){
// 新增任务
qsrand(time(NULL));
int r = qrand() % 1000000 + 1000000;
QString code = "code"+QString::number(r);
MTask *task = new MTask();
task->name = "新建任务";
task->code = code;
task->defaultUserAgent = Database::getInstance()->getRandomUserAgent();
if(!address.isNull()){
task->addressList = address.split("\n");
}
setTask(task);
}
void Tab::createTaskManage(){
bool create = true;
for (int i = 0; i < this->count(); ++i) {
if("TaskManage"==QString(this->widget(i)->metaObject()->className())){
create = false;
this->setCurrentIndex(i);
break;
}
}
if(create){
TaskManage *page = new TaskManage(this);
addTab(page,formatTabName("任务管理"));
setCurrentWidget(page);
connect(page,&TaskManage::notifyPageTaskData,this,[this](const QString &taskName,const QString &taskCode){
TaskData *page = new TaskData(taskName,taskCode,this);
addTab(page,formatTabName(taskName));
setCurrentWidget(page);
});
connect(page,&TaskManage::notifyEditCustomTask,this,[this](MTask *task){
// 编辑任务
setTask(task);
});
}
}
QString Tab::formatTabName(const QString &name){
if(name.length()>15){
return " "+name.mid(0,15) + "... ";
}else{
return " "+name+" ";
}
}
void Tab::setTask(MTask *task){
Task *page = new Task(task,this);
addTab(page,formatTabName(task->name));
setCurrentWidget(page);
connect(page,&Task::notifyChangeTabName,this,[this,page](const QString &name){
this->setTabText(this->indexOf(page),formatTabName(name));
});
connect(page,&Task::notifyChangeTabIcon,this,[this,page](const QIcon &icon){
this->setTabIcon(this->indexOf(page),icon);
});
}
void Tab::onCloseTab(int index){
QWidget *page = widget(index);
if("Index"==QString(page->metaObject()->className())){
}else{
removeTab(index);
page->deleteLater();
// delete currentWidget;
// if (WebView *view = webView(index)) {
// bool hasFocus = view->hasFocus();
// removeTab(index);
// if (hasFocus && count() > 0)
// currentWebView()->setFocus();
// if (count() == 0)
// createTab();
// view->deleteLater();
// }
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。