Exemplo n.º 1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    //TODELETE

    ui->setupUi(this);
    this->setMinimumSize(800,650);

    /******************************************************************************************************/
    // Instanciation of differents windows
    /******************************************************************************************************/
    createListWindow_ = new CreateListWindow();
    createProjectWindow_ = new CreateProjectWindow();
    modifyListWindow_ = new ModifyListWindow();
    modifyTaskWindow_ = new ModifyTaskWindow();
    aboutWindow_ = new AboutWindow();
    createTaskWindow_ = new CreateTaskWindow();

    /* QListView definition for the history */
    myListView = new QListView();
    historyModel = new QStandardItemModel;
    myListView->setModel(historyModel);
    myListView->setAlternatingRowColors(true);

    /******************************************************************************************************/
    /* Creats layouts */
    /******************************************************************************************************/
    QLayout * projectLayout = new QVBoxLayout();
    QLayout * taskLayout = new QVBoxLayout();
    QLayout * listLayout = new QVBoxLayout();
    QLayout * actionsLayout = new QVBoxLayout();
    QLayout * historyLayout = new QVBoxLayout();

    /******************************************************************************************************/
    /* Creats groupBox */
    /******************************************************************************************************/
    QGroupBox * projectGroup = new QGroupBox("Projet");
    QGroupBox * taskGroup = new QGroupBox("Tâches");
    QGroupBox * listGroup = new QGroupBox("Listes");
    QGroupBox * actionsGroup = new QGroupBox("Actions");
    QGroupBox * historyGroup = new QGroupBox("Historique");

    /******************************************************************************************************/
    /* Creats buttons */
    /******************************************************************************************************/

    createProject = new QPushButton("Créer un nouveau projet");
    this->setButtonIcon(createProject,(std::string)":Images/project_icon");

    createTask = new QPushButton("Créer une tâche");
    this->setButtonIcon(createTask,(std::string)":Images/tache_icon");

    modifyTask = new QPushButton("Modifier une tâche");
    this->setButtonIcon(modifyTask,(std::string)":Images/engrenage_icon");

    createList = new QPushButton("Créer une liste");
    this->setButtonIcon(createList,(std::string)":Images/liste_icon");

    modifyList = new QPushButton("Modifier une liste");
    this->setButtonIcon(modifyList,(std::string)":Images/engrenage_icon");

    deleteItem = new QPushButton("Supprimer un élément");
    this->setButtonIcon(deleteItem,(std::string)":Images/minus_icon");

    up = new QPushButton("Monter");
    this->setButtonIcon(up,(std::string)":Images/up_icon");

    down = new QPushButton("Descendre");
    this->setButtonIcon(down,(std::string)":Images/down_icon");

    history = new QPushButton("Historique");
    this->setButtonIcon(history,(std::string)":Images/history_icon");

    /******************************************************************************************************/
    /* Adding buttons to layouts */
    /******************************************************************************************************/
    projectLayout->addWidget(createProject);

    listLayout->addWidget(createList);
    listLayout->addWidget(modifyList);

    taskLayout->addWidget(createTask);
    taskLayout->addWidget(modifyTask);

    actionsLayout->addWidget(deleteItem);
    actionsLayout->addWidget(up);
    actionsLayout->addWidget(down);

    historyLayout->addWidget(history);
    historyLayout->addWidget(myListView);

    /******************************************************************************************************/
    /* Adding layouts to GroupBox */
    /******************************************************************************************************/
    projectGroup->setLayout(projectLayout);

    taskGroup->setLayout(taskLayout);
    listGroup->setLayout(listLayout);
    actionsGroup->setLayout(actionsLayout);
    historyGroup->setLayout(historyLayout);

    /******************************************************************************************************/
    /* Adding QGroupBox to QToolBar */
    /******************************************************************************************************/
    ui->mainToolBar->addWidget(projectGroup);
    ui->mainToolBar->addWidget(taskGroup);
    ui->mainToolBar->addWidget(listGroup);
    ui->mainToolBar->addWidget(actionsGroup);

    /* Adding buttons to ToolBar */
    ui->toolBar->addWidget(historyGroup);

    /******************************************************************************************************/
    // Slots and signals definition
    /******************************************************************************************************/

    //Create a project
    QObject::connect(ui->actionNewProject, SIGNAL(triggered()), this, SLOT(slotCreateProjectWindow()));
    QObject::connect(createProject, SIGNAL(clicked()), this, SLOT(slotCreateProjectWindow()));
    QObject::connect(createProjectWindow_, SIGNAL(createProject(Liste *)), this, SLOT(addProject(Liste *)));

    //Loading Project
    QObject::connect(ui->actionOpenProject, SIGNAL(triggered()), this, SLOT(slotOpenProjectWindow()));

    //Loading Template
    QObject::connect(ui->actionOpenTemplate, SIGNAL(triggered()), this, SLOT(slotOpenTemplateWindow()));

    //Create a task
    QObject::connect(ui->actionCreateTask, SIGNAL(triggered()), this, SLOT(slotCreateTaskWindow()));
    QObject::connect(createTask, SIGNAL(clicked()), this, SLOT(slotCreateTaskWindow()));
    QObject::connect(createTaskWindow_, SIGNAL(transferTask(Tache *)), this, SLOT(addTask(Tache *)));

    //Delete an element
    QObject::connect(deleteItem, SIGNAL(clicked()), this, SLOT(deleteElement()));

    //Modify a task
    QObject::connect(ui->actionModifyTask, SIGNAL(triggered()), this, SLOT(slotModifyTaskWindow()));
    QObject::connect(modifyTask, SIGNAL(clicked()), this, SLOT(slotModifyTaskWindow()));
    QObject::connect(modifyTaskWindow_, SIGNAL(modifyTask(Tache*,Tache*)), this, SLOT(modifyTaskAt(Tache*,Tache*)));

    //Create a list of tasks
    QObject::connect(ui->actionCreateList, SIGNAL(triggered()), this, SLOT(slotCreateListWindow()));
    QObject::connect(createList, SIGNAL(clicked()), this, SLOT(slotCreateListWindow()));
    QObject::connect(createListWindow_, SIGNAL(createList(Liste *)), this, SLOT(addList(Liste *)));

    //Modify a list of tasks
    QObject::connect(ui->actionModifyList, SIGNAL(triggered()), this, SLOT(slotModifyListWindow()));
    QObject::connect(modifyList, SIGNAL(clicked()), this, SLOT(slotModifyListWindow()));
    QObject::connect(modifyListWindow_, SIGNAL(modifyList(Liste*,Liste*)), this, SLOT(modifyListAt(Liste*,Liste*)));

    //Save project
    QObject::connect(ui->actionSaveUnList, SIGNAL(triggered()), this, SLOT(saveProject()));

    //Save template
    QObject::connect(ui->actionSaveTemplate, SIGNAL(triggered()), this, SLOT(saveTemplate()));

    //About Window
    QObject::connect(ui->actionAboutPeaceTache, SIGNAL(triggered()), this, SLOT(slotAboutWindow()));

    //UP element
    QObject::connect(ui->actionUp, SIGNAL(triggered()), this, SLOT(upElement()));
    QObject::connect(up, SIGNAL(clicked()), this, SLOT(upElement()));

    //DOWN element
    QObject::connect(ui->actionDown, SIGNAL(triggered()), this, SLOT(downElement()));
    QObject::connect(down, SIGNAL(clicked()), this, SLOT(downElement()));

    //history button
    QObject::connect(history, SIGNAL(clicked()), this, SLOT(showOrHideHistory()));
    //close window
    QObject::connect((ui->actionQuit), SIGNAL(triggered()), this, SLOT(closeApp()));

    QObject::connect((ui->treeView), SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));

    ui->treeView->setAnimated(true);
    ui->treeView->setHeaderHidden(true);

    /******************************************************************************************************/
    //Disable buttons and menus
    /******************************************************************************************************/
    createList->setEnabled(false);
    createTask->setEnabled(false);
    modifyTask->setEnabled(false);
    modifyList->setEnabled(false);
    deleteItem->setEnabled(false);
    up->setEnabled(false);
    down->setEnabled(false);

    this->loadCache();
}
Exemplo n.º 2
0
MainWindow::MainWindow(QWidget *parent) :
        QWidget(parent) {
    this->setWindowTitle("环境变量编辑器");
    /***************************************************
     全局布局控制
     */
    hblMain = new QHBoxLayout(this);
    vblRight = new QVBoxLayout(this);
    vblLeft = new QVBoxLayout(this);
    hblMain->addLayout(vblLeft);
    hblMain->addLayout(vblRight);
    /*******************************************************
     左侧布局
     */
    lbTableView = new QLabel("当前系统环境变量:", this);
    vblLeft->addWidget(lbTableView);
    tvValueList = new QTableView();
    vblLeft->addWidget(tvValueList);
    lbDetailTittle = new QLabel("变量信息:", this);
    vblLeft->addWidget(lbDetailTittle);
    lbPathDetail = new QLabel("变量信息:", this);
    vblLeft->addWidget(lbPathDetail);
    lbPathDetail->setGeometry(QRect(328, 240, 329, 27 * 4));  //四倍行距
    lbPathDetail->setWordWrap(true);  //自动换行
    lbPathDetail->setAlignment(Qt::AlignTop);
    /*******************************************************
     右侧布局
     */
    lbPathDescribe = new QLabel("Path设置:", this);
    vblRight->addWidget(lbPathDescribe);
    pbShowPath = new QPushButton("显示Path信息");  //显示path
    vblRight->addWidget(pbShowPath);
    pbEiditPath = new QPushButton("编辑Path路径");  //修改path
    vblRight->addWidget(pbEiditPath);

    //*****************************************************************

    lbBackDescribe = new QLabel("环境适配:");
    vblRight->addWidget(lbBackDescribe);
    pbSetBack = new QPushButton("备份当前环境");  //备份环境
    vblRight->addWidget(pbSetBack);
    pbUseBack = new QPushButton("还原到指定环境");  //还原环境
    vblRight->addWidget(pbUseBack);
    pbCheckIN = new QPushButton("导入特定环境变量");  //导入环境
    vblRight->addWidget(pbCheckIN);
    pbCheckOut = new QPushButton("导出指定环境变量"); //导出环境
    vblRight->addWidget(pbCheckOut);

    //*****************************************************************

    lbEiditDescribe = new QLabel("变量操作:");
    vblRight->addWidget(lbEiditDescribe);
    pbNewValue = new QPushButton("新建环境变量");  //新建变量
    vblRight->addWidget(pbNewValue);
    pbEiditValue = new QPushButton("编辑选中变量");  //编辑变量
    vblRight->addWidget(pbEiditValue);
    pbDelValue = new QPushButton("删除选中变量");  //删除变量
    vblRight->addWidget(pbDelValue);

    //*****************************************************************
    lbEiditFunction = new QLabel(" ");
    vblRight->addWidget(lbEiditFunction);
    pbAbout = new QPushButton("关于…");//关于
    vblRight->addWidget(pbAbout);
    pbExit = new QPushButton("退出"); //退出
    vblRight->addWidget(pbExit);

    /******************************************
     //        环境变量池
     */
    //显示变量
    slotRefrehValue();

    //通过是否可以新建环境变量判断是否以管理员身份启动
    reg->setValue("testAdminPermissions", "test");
    if (reg->value("testAdminPermissions", false).toBool()) {

        reg->remove("testAdminPermissions");
        isAdimin = true;
        //判断back目录是否存在,若没有提示用户备份!
        QDir dir;
        if (!dir.exists("./back/")) {
            switch (QMessageBox::information(this, "备份提醒",
                    "程序当前目录下找不到back文件夹,您可能从未对环境变量进行备份,为了保证操作安全,强烈建议您备份当前环境变量以减少误操作所带来的困扰!",
                    "立即备份!", "暂不需要!", 0, 1)) {
            case 0:
                slotSetBack();
                break;
            case 1:
                break;

            }

        }
    } else {
        QMessageBox::information(NULL, "未获得UAC管理员权限",
                "未使用UAC管理员权限开启本程序,由于Windows系统的限制,你可能只能查看变量内容而无法对其编辑");
        isAdimin = false;

    }

    //显示选中变量概要
    connect(tvValueList, SIGNAL(clicked(QModelIndex)), this,
            SLOT(slotGetClickedLine()));

    //槽
    //显示Path信息
    connect(pbShowPath, SIGNAL(clicked()), this, SLOT(slotShowPath()));
    //添加按钮槽
    connect(pbNewValue, SIGNAL(clicked()), this, SLOT(slotCreateWindow()));
    connect(pbEiditValue, SIGNAL(clicked()), this, SLOT(slotEiditWindow()));
    connect(pbEiditPath, SIGNAL(clicked()), this, SLOT(slotPathWindow()));

    //删除按钮槽
    connect(pbDelValue, SIGNAL(clicked()), this, SLOT(slotRemoveValue()));
    //备份
    connect(pbSetBack, SIGNAL(clicked()), this, SLOT(slotSetBack()));
    //还原
    connect(pbUseBack, SIGNAL(clicked()), this, SLOT(SlotGetBackWindow()));
    //导出
    connect(pbCheckOut, SIGNAL(clicked()), this, SLOT(slotExportWindow()));
    //导入
    connect(pbCheckIN, SIGNAL(clicked()), this, SLOT(slotImportWindow()));
    //退出
    connect(pbExit, SIGNAL(clicked()), this, SLOT(close()));
    //关于
    connect(pbAbout, SIGNAL(clicked()), this, SLOT(slotAboutWindow()));
}