Exemple #1
0
ContentWidget::ContentWidget(QWidget *parent)
	:QWidget(parent)
{
    QPalette palette;
	palette.setBrush(QPalette::Window, QBrush(Qt::white));
    setPalette(palette);
    setAutoFillBackground(true);
	
	main_splitter = new QSplitter();
	main_splitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	main_splitter->setOrientation(Qt::Horizontal);
	main_splitter->setHandleWidth(1);
	main_splitter->setStyleSheet("QSplitter::handle{background:lightgray;}");

	this->initLeft();
	this->initRight();
	this->initRightTop();
	this->initRightCenter();
	this->initRightCenterFunction();
	this->initRightBottom();

	right_splitter->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
	right_splitter->setOrientation(Qt::Vertical);
	right_splitter->setHandleWidth(1);
	right_splitter->setStyleSheet("QSplitter::handle{background:lightgray;}");

	right_top_widget->setFixedSize(250, 130);
	right_center_widget->setFixedSize(250, 90);
	right_bottom_widget->setFixedSize(250, 30);
	right_splitter->addWidget(right_top_widget);
	right_splitter->addWidget(right_center_widget);
	right_splitter->addWidget(right_center_function_widget);
	right_splitter->addWidget(right_bottom_widget);

	main_splitter->addWidget(left_widget);
	main_splitter->addWidget(right_splitter);

	//½ûÖ¹Í϶¯
	for(int i = 0; i<right_splitter->count();i++) 
	{ 
		QSplitterHandle *handle = right_splitter->handle(i); 
		handle->setEnabled(false); 
	} 

	for(int i = 0; i<main_splitter->count();i++) 
	{ 
		QSplitterHandle *handle = main_splitter->handle(i); 
		handle->setEnabled(false); 
	}

	QHBoxLayout *main_layout = new QHBoxLayout();
	main_layout->addWidget(main_splitter);
	main_layout->setSpacing(0);
	main_layout->setContentsMargins(0, 0, 0, 0);

	setLayout(main_layout);
	
	this->translateLanguage();
}
SettingWidget::SettingWidget(QString cur_desktop, QWidget *parent) :
    QWidget(parent), desktop(cur_desktop)
{
    this->setFixedSize(900, 403);
    //set white background color
    this->setAutoFillBackground(true);
    QPalette palette;
    palette.setBrush(QPalette::Window, QBrush(Qt::white));
    this->setPalette(palette);

//    this->mainwindow_width = 850;
//    this->mainwindow_height = 600;

    stacked_widget = new QStackedWidget(this);//stacked_widget will delete when SettingWidget delete
    theme_widget = NULL;
    icon_widget = NULL;
    mouse_widget = NULL;
    voice_widget = NULL;
    animation_widget = NULL;
    launcher_widget = NULL;
    panel_widget = NULL;
    window_widget = NULL;
    font_widget = NULL;
    touchpad_widget = NULL;
    deadpixel_widget = NULL;
    conserve_widget = NULL;
    nautilus_widget = NULL;

    h_splitter = new QSplitter();
    h_splitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    h_splitter->setOrientation(Qt::Horizontal);
    h_splitter->setHandleWidth(1);

    this->initIndividuationWidget();
    this->initDesktopWidget();
    this->initFontWidget();
    this->initOptionWidget();
    this->initOtherWidget();

    individuation_widget->setFixedSize(170, 426);
    dekstop_widget->setFixedSize(170, 426);
    fonts_widget->setFixedSize(170, 426);
    option_widget->setFixedSize(170, 426);
    h_splitter->addWidget(individuation_widget);
    h_splitter->addWidget(dekstop_widget);
    h_splitter->addWidget(fonts_widget);
    h_splitter->addWidget(option_widget);
    h_splitter->addWidget(other_widget);

    for(int i = 0; i<h_splitter->count();i++)
    {
        QSplitterHandle *handle = h_splitter->handle(i);
        handle->setEnabled(false);
    }

//    for(int i = 0; i<v_splitter->count();i++)
//    {
//        QSplitterHandle *handle = v_splitter->handle(i);
//        handle->setEnabled(false);
//    }

//    QHBoxLayout *main_layout = new QHBoxLayout();
//    main_layout->addWidget(v_splitter);
//    main_layout->setSpacing(0);
//    main_layout->setContentsMargins(0, 0, 0, 0);


//    connect(theme_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(icon_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(mouse_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(voice_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(animation_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(launcher_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(panel_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(window_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(font_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(touchpad_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(deadpixel_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
//    connect(nautilus_widget, SIGNAL(showSettingMainWidget()), this, SLOT(displaySettingHomePage()));
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
    setWindowTitle(QCoreApplication::applicationName());
    ui.setupUi(this);

    // setup preferences dialog
    connect(&preferences,   SIGNAL(accepted()),                     this,   SLOT(getApplicationSettings()));

    connect(&builder,   SIGNAL(highlightLine(const QString &,
                                             int,
                                             int,
                                             const QString &)),

            this,       SLOT(highlightFileLine(const QString &,
                                               int,
                                               int)));

    connect(&builder,   SIGNAL(finished()),     this,           SLOT(setBuildAvailable()));
    connect(&builder,   SIGNAL(buildError()),   &preferences,   SLOT(showPreferences()));

    parser = language.parser();

    connect(&preferences, SIGNAL(updateColors()),               this,   SLOT(recolorProjectView()));
    connect(&preferences, SIGNAL(updateFonts(const QFont &)),   this,   SLOT(recolorProjectView()));

    connect(&preferences, SIGNAL(updateFonts(const QFont &)),   this,   SLOT(recolorBuildManager()));

    connect(&preferences, SIGNAL(accepted()),                   ui.editorTabs,   SIGNAL(accepted()));
    connect(&preferences, SIGNAL(updateColors()),               ui.editorTabs,   SIGNAL(updateColors()));
    connect(&preferences, SIGNAL(updateFonts(const QFont &)),   ui.editorTabs,   SIGNAL(updateFonts(const QFont &)));

    recolorProjectView();
    recolorBuildManager();

    // project editor tabs
    ui.finder->connectFileManager(ui.editorTabs);
    QSplitterHandle *hndl = ui.splitter->handle(1);
    hndl->setEnabled(false);

    connect(ui.editorTabs, SIGNAL(fileUpdated(int)),    this,   SLOT(setProject()));

    // File Menu
    connect(ui.action_New,              SIGNAL(triggered()),    ui.editorTabs,  SLOT(newFile()));
    connect(ui.actionNew_From_File,     SIGNAL(triggered()),    ui.editorTabs,  SLOT(newFromFile()));
    connect(ui.actionNew_From_Template, SIGNAL(triggered()),    this,           SLOT(newFromTemplate()));
    connect(ui.action_Open,             SIGNAL(triggered()),    ui.editorTabs,  SLOT(open()));

    connect(ui.action_Save,SIGNAL(triggered()),ui.editorTabs,SLOT(save()));
    connect(ui.actionSave_As,SIGNAL(triggered()),ui.editorTabs,SLOT(saveAs()));
    connect(ui.actionSave_All,SIGNAL(triggered()),ui.editorTabs,SLOT(saveAll()));

    ui.actionPrint->setEnabled(true);
    connect(ui.actionPrint,SIGNAL(triggered()),this,SLOT(printFile()));

    ui.action_Zip->setEnabled(true);
    connect(ui.action_Zip,SIGNAL(triggered()),this,SLOT(zipFiles()));

    recentFiles = findChildren<QAction *>(QRegExp("action_[0-9]+_File"));
    for (int i = 0; i < recentFiles.size(); i++)
        connect(recentFiles.at(i), SIGNAL(triggered()),this, SLOT(openRecentFile()));
    
    connect(ui.action_Close,       SIGNAL(triggered()),    ui.editorTabs, SLOT(closeFile()));
    connect(ui.actionClose_All,    SIGNAL(triggered()),    ui.editorTabs, SLOT(closeAll()));
    connect(ui.action_Quit,        SIGNAL(triggered()),    this,          SLOT(quitProgram()));

    connect(ui.editorTabs, SIGNAL(saveAvailable(bool)),    this,          SLOT(setSaveAvailable(bool)));
    connect(ui.editorTabs, SIGNAL(saveAvailable(bool)),    this,          SLOT(setSaveAvailable(bool)));
    connect(ui.editorTabs, SIGNAL(closeAvailable(bool)),   this,          SLOT(setCloseAvailable(bool)));
    connect(ui.editorTabs, SIGNAL(closeAvailable(bool)),   this,          SLOT(setCloseAvailable(bool)));
    connect(ui.editorTabs, SIGNAL(closeAvailable(bool)),   this,          SLOT(setBuildAvailable(bool)));

    // Edit Menu
    connect(ui.action_Undo,        SIGNAL(triggered()), ui.editorTabs, SLOT(undo()));
    connect(ui.action_Redo,        SIGNAL(triggered()), ui.editorTabs, SLOT(redo()));

    connect(ui.action_Cut,         SIGNAL(triggered()), ui.editorTabs, SLOT(cut()));
    connect(ui.action_Copy,        SIGNAL(triggered()), ui.editorTabs, SLOT(copy()));
    connect(ui.action_Paste,       SIGNAL(triggered()), ui.editorTabs, SLOT(paste()));
    connect(ui.actionSelect_All,   SIGNAL(triggered()), ui.editorTabs, SLOT(selectAll()));

    connect(ui.action_Find,        SIGNAL(triggered()), ui.finder, SLOT(showFinder()));
    connect(ui.actionFind_Next,    SIGNAL(triggered()), ui.finder, SLOT(findNext()));
    connect(ui.actionFind_Previous,SIGNAL(triggered()), ui.finder, SLOT(findPrevious()));

    connect(ui.actionPreferences,  SIGNAL(triggered()), &preferences, SLOT(showPreferences()));

    connect(ui.editorTabs, SIGNAL(undoAvailable(bool)), ui.action_Undo,SLOT(setEnabled(bool)));
    connect(ui.editorTabs, SIGNAL(redoAvailable(bool)), ui.action_Redo,SLOT(setEnabled(bool)));
    connect(ui.editorTabs, SIGNAL(copyAvailable(bool)), ui.action_Cut,SLOT(setEnabled(bool)));
    connect(ui.editorTabs, SIGNAL(copyAvailable(bool)), ui.action_Copy,SLOT(setEnabled(bool)));

    // View Menu
    connect(ui.actionShow_Browser, SIGNAL(triggered()), this, SLOT(showBrowser()));
    connect(ui.actionBigger_Font,  SIGNAL(triggered()), this, SLOT(fontBigger()));
    connect(ui.actionSmaller_Font, SIGNAL(triggered()), this, SLOT(fontSmaller()));

    ui.actionBigger_Font->setShortcuts(QList<QKeySequence>() << QKeySequence::ZoomIn
                                                             << Qt::CTRL+Qt::Key_Equal);

    // Project Menu
    connect(ui.actionMemory_Map,SIGNAL(triggered()), this, SLOT(spawnMemoryMap()));
    connect(ui.actionBuild,     SIGNAL(triggered()), this, SLOT(programBuild()));
    connect(ui.actionRun,       SIGNAL(triggered()), this, SLOT(programRun()));
    connect(ui.actionWrite,     SIGNAL(triggered()), this, SLOT(programWrite()));
    connect(ui.actionTerminal,  SIGNAL(triggered()), this, SLOT(spawnTerminal()));

    // Help Menu
    connect(ui.actionPropeller_Quick_Reference, SIGNAL(triggered()), this, SLOT(propellerQuickReference()));
    connect(ui.actionPropeller_Datasheet,       SIGNAL(triggered()), this, SLOT(propellerDatasheet()));
    connect(ui.actionPropeller_Manual,          SIGNAL(triggered()), this, SLOT(propellerManual()));
    connect(ui.actionPropBASIC_Manual,          SIGNAL(triggered()), this, SLOT(propBasicManual()));
    connect(ui.action_About,                    SIGNAL(triggered()), this, SLOT(about()));

    // Toolbar Extras
    cbPort = new QComboBox(this);
    cbPort->setLayoutDirection(Qt::LeftToRight);
    cbPort->setToolTip(tr("Select Serial Port"));
    cbPort->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    ui.toolBar->addWidget(cbPort);

    connect(ui.projectview, SIGNAL(showFileLine(QString, int)),
            this,           SLOT(highlightFileLine(QString, int)));

    updateRecentFileActions();

    connect(ui.editorTabs, SIGNAL(sendMessage(const QString &)),   this,SLOT(showMessage(const QString &)));
    connect(ui.finder,     SIGNAL(sendMessage(const QString &)),   this,SLOT(showMessage(const QString &)));

    restoreGeometry(QSettings().value("windowSize").toByteArray());

    getApplicationSettings();

    connect(&manager, SIGNAL(portListChanged()), this, SLOT(updatePorts()));
    manager.enablePortMonitor(true);
    updatePorts();

    
    QSettings settings;
    QString lastport = settings.value("lastPort", QString()).toString();
    if (!lastport.isEmpty())
    {
        int index = cbPort->findText(lastport);
        if (index != -1)
            cbPort->setCurrentIndex(index);
    }

    ui.editorTabs->newFile();
    loadSession();

    installEventFilter(this);
    statusBar();
}
void mafViewCompoundConfigurator::parseDocument(QDomNode current, QObject *parent) {
    QDomNodeList dnl = current.childNodes();
    for (int n=0; n < dnl.count(); ++n) {
        QDomNode node = dnl.item(n);
        if (node.nodeType() == QDomNode::ElementNode) {
            QDomElement ce = node.toElement();
            QDomNamedNodeMap attributes = ce.attributes();
            QString elem_name = ce.tagName();
            if (elem_name == "splitter") {
                mafSplitter *splitter = new mafSplitter(Qt::Horizontal, (QWidget *)parent);
                if (parent == NULL) {
                    // parent is the root object, this is the first splitter created
                    m_RootObject = splitter;
                }
                QString sepThikness = attributes.namedItem("separatorThikness").nodeValue();
                QString sepEnabled = attributes.namedItem("enableSeparator").nodeValue();
                splitter->setHandleWidth(sepThikness.toInt());
                QString orientation = attributes.namedItem("orientation").nodeValue();
                if (orientation == "vertical") {
                    // Check only for vertical, horizontal is the default.
                    splitter->setOrientation(Qt::Vertical);
                }
                QStringList sizesString = attributes.namedItem("sizes").nodeValue().split(",", QString::SkipEmptyParts);
                QList<int> sizes;
                for (int s = 0; s < sizesString.count(); ++s) {
                    sizes.append(sizesString[s].toInt());
                }
                splitter->setSizes(sizes);
                // Check if there are children and parse them...
                QDomNodeList splitter_dnl = node.childNodes();
                if (splitter_dnl.count() > 0) {
                    parseDocument(node, splitter);
                }
                QSplitterHandle *handler = splitter->handle(1);
                handler->setEnabled(sepEnabled.toInt() != 0);
            } else if (elem_name == "view") {
                // view objects are added at the parent splitter.
                QString viewClassType = attributes.namedItem("classtype").nodeValue();
                // Instantiate the class type
                mafCore::mafObjectBase *obj = mafNEWFromString(viewClassType);
                // Then extract all the attributes representing the object's properties.
                int s = attributes.size();
                int i = 0;
                for (; i < s; ++i) {
                    QDomNode n(attributes.item(i));
                    if (n.nodeName() != "classtype") {
                        QByteArray ba(n.nodeName().toAscii());
                        bool isOk(obj->setProperty(ba.constData(), n.nodeValue()));
                        if (!isOk) {
                            qWarning() << mafTr("Problem assigning property named: %1 to view of type: %2").arg(n.nodeName(), viewClassType);
                        }
                    }
                }
                mafSplitter *parentSplitter = qobject_cast<mafSplitter *>(parent);
                if (parentSplitter) {
                    // and add it to the splitter.
                    parentSplitter->addView(obj);
                }
                // Check if there are children and parse them...
                QDomNodeList view_dnl = node.childNodes();
                if (view_dnl.count() > 0) {
                    parseDocument(node, obj);
                }
                // The splitter retain the view object, so we can release the instance.
                mafDEL(obj);
            } else if (elem_name == "visualpipe") {
                // Visual pipe to plug into the previous created view...
                QVariant visualPipeClassType(attributes.namedItem("classtype").nodeValue());
                QString dataType(attributes.namedItem("datatype").nodeValue());
                QVariantHash h;
                h.insert(dataType, visualPipeClassType);
                mafCore::mafObjectBase *viewObj = dynamic_cast<mafCore::mafObjectBase *>(parent);
                if (viewObj) {
                    viewObj->setProperty("visualPipeHash", h);

                    int s = attributes.size();
                    int i = 0;
                    QVariantHash propertyHash;
                    for (; i < s; ++i) {
                        QDomNode n(attributes.item(i));
                        if (n.nodeName() != "classtype" && n.nodeName() != "datatype") {
                            propertyHash.insert(n.nodeName(), n.nodeValue());
                        }
                    }
                    if (propertyHash.size() > 0) {
                        // Found some custom properties used to initialize the pipe
                        QString vp(visualPipeClassType.toString());
                        bool isOk(viewObj->metaObject()->invokeMethod(viewObj, "plugPipeParametersHashItem",
                                                    Q_ARG(QString, vp),
                                                    Q_ARG(QVariantHash, propertyHash)));
                        if (!isOk) {
                            qWarning() << mafTr("Problem invoking method used to plug the pipe's parameter for pipe: %1").arg(visualPipeClassType.toString());
                        }
                    }
                }
            } else {
                qWarning() << mafTr("Unrecognized element named: ") << elem_name;
            }
        }
    }
}