コード例 #1
0
ファイル: Main.cpp プロジェクト: rkreutz/UofT-ECE244
int main()
{
    string line , command , str;
    NodeList list_of_nodes;
	while(1){
		cout << "> ";
		getline ( cin , line);

		if ( cin.eof() ) {
			cout << endl;			//Whend Ctrl + D is pressed it will print endl and close the program.
			break;
		}

		stringstream lineStream (line);

		lineStream >> command;

		if (command == "add") {			//if the command matches with the string it will run the function.
            add ( lineStream , &list_of_nodes);
		}

		else if (command == "changeR") {	//same
			changeR ( lineStream , &list_of_nodes);
		}

		else if (command == "find") {		//same
			find ( lineStream , &list_of_nodes);
		}

		else if (command == "list") {		//same
			list ( lineStream , &list_of_nodes);
		}

		else if (command == "clear") {		//same
            clear ( lineStream , &list_of_nodes);
		}

		else if (command == "remove") {
            remove (lineStream , &list_of_nodes);
		}

		else {
			cout << "Error: unknown command\n";		//if the command is not recognized: Error message.
		}
	}
	return 0;
}
コード例 #2
0
ファイル: interface.cpp プロジェクト: reolyze/wallgen
interface::interface(QWidget *parent) :
    QWidget(parent)
{

    // FUNCTIONAL VARIABLES
    termindex = 0;
    saveloadPath = QDir::currentPath();

    // FUNCTIONAL OBJECTS
    f = new hex3Function();
    c = new ColorWheel();


    // ORGANIZATIONAL ELEMENTS
    editconst = new QGroupBox(tr("Function Constants"), this);          //create elements
    interfaceLayout = new QVBoxLayout(this);
    topbarLayout = new QHBoxLayout();
    propsBox = new QGroupBox(tr("Image Properties"), this);
    displayWidget = new QWidget(this);
    genBoxWidget = new QWidget(this);

    topbarLayout->addWidget(genBoxWidget);
    topbarLayout->addWidget(displayWidget);
    topbarLayout->addWidget(propsBox);
    interfaceLayout->addLayout(topbarLayout);                       //lay out vertically
    interfaceLayout->addWidget(editconst);
    setLayout(interfaceLayout);

    // INPUT VALIDATORS (NUMERICAL)
    doubleValidate = new QDoubleValidator(-9999999.0, 9999999.0, 5, this);
    intValidate = new QIntValidator(-9999999, 9999999, this);
    posdoubleValidate = new QDoubleValidator(1.0, 9999999.0, 5, this);
    posintValidate = new QIntValidator(1, 9999999, this);
    numtermsValidate = new QIntValidator(1, 99, this);
    dimValidate = new QIntValidator(1, 2000, this);

    // EDITCONST SUBELEMENTS
    currtermL = new QLabel(editconst);                              //create labels
    currtermL->setText(tr("Term"));
    nL = new QLabel(editconst);
    mL = new QLabel(editconst);
    aL = new QLabel(editconst);
    rL = new QLabel(editconst);
    scaleaL = new QLabel(tr("sa"), editconst);
    scalerL = new QLabel(tr("sr"), editconst);
    refreshLabels();
    nE = new QLineEdit(editconst);                              //create input boxes
    mE = new QLineEdit(editconst);
    aE = new QLineEdit(editconst);
    rE = new QLineEdit(editconst);
    scaleaE = new QLineEdit(editconst);
    scalerE = new QLineEdit(editconst);
    currtermE = new QSpinBox(editconst);
    espacer1 = new QSpacerItem(10, 15);
    espacer2 = new QSpacerItem(10, 15);
    espacer3 = new QSpacerItem(10, 15);
    espacer4 = new QSpacerItem(10, 15);
    espacer5 = new QSpacerItem(130, 15);
    espacer6 = new QSpacerItem(2, 0);
    espacer7 = new QSpacerItem(15, 15);
    espacer8 = new QSpacerItem(8, 15);
    loadButton = new QPushButton(tr("Load..."), editconst);
    saveButton = new QPushButton(tr("Save"), editconst);
    currtermE->setMaximum(4);
    currtermE->setMinimum(1);
    nE->setFixedWidth(75);
    mE->setFixedWidth(75);
    rE->setFixedWidth(75);
    aE->setFixedWidth(75);
    scaleaE->setFixedWidth(75);
    scalerE->setFixedWidth(75);
    nL->setFixedWidth(18);
    mL->setFixedWidth(20);
    rL->setFixedWidth(18);
    aL->setFixedWidth(18);
    scaleaL->setFixedWidth(18);
    scalerL->setFixedWidth(18);
    nE->setValidator(intValidate);
    mE->setValidator(intValidate);
    rE->setValidator(doubleValidate);
    aE->setValidator(doubleValidate);
    scaleaE->setValidator(doubleValidate);
    scalerE->setValidator(doubleValidate);


    editconstLayoutStack = new QVBoxLayout(editconst);  //initialize layout
    editconstLayout = new QHBoxLayout();
    editconstLayoutLower = new QHBoxLayout();
    editconstLayoutLower->setAlignment(Qt::AlignRight);
    editconstLayout->setAlignment(Qt::AlignRight);

    editconstLayout->addWidget(currtermL);              //fill layouts
    editconstLayout->addWidget(currtermE);
    editconstLayout->addItem(espacer1);
    editconstLayout->addWidget(nL);
    editconstLayout->addWidget(nE);
    editconstLayout->addItem(espacer2);
    editconstLayout->addWidget(mL);
    editconstLayout->addWidget(mE);
    editconstLayout->addItem(espacer3);
    editconstLayout->addWidget(rL);
    editconstLayout->addWidget(rE);
    editconstLayout->addItem(espacer4);
    editconstLayout->addWidget(aL);
    editconstLayout->addWidget(aE);
    editconstLayoutLower->addItem(espacer8);
    editconstLayoutLower->addWidget(loadButton);
    editconstLayoutLower->addItem(espacer7);
    editconstLayoutLower->addWidget(saveButton);
    editconstLayoutLower->addItem(espacer5);
    editconstLayoutLower->addWidget(scalerL);
    editconstLayoutLower->addWidget(scalerE);
    editconstLayoutLower->addItem(espacer6);
    editconstLayoutLower->addWidget(scaleaL);
    editconstLayoutLower->addWidget(scaleaE);
    editconstLayoutStack->addLayout(editconstLayout);
    editconstLayoutStack->addLayout(editconstLayoutLower);
    editconst->setLayout(editconstLayoutStack);

    // GENBOX SUBELEMENTS
    genBox = new QGroupBox(tr("Image Generation"), genBoxWidget);
    functionSel = new QComboBox(genBox);        //initialize elements
    colorwheelSel = new QComboBox(genBox);
    functionL = new QLabel(genBox);
    colorwheelL = new QLabel(genBox);
    numtermsL = new QLabel(tr("<i>No. Terms</i>"), genBox);
    numtermsE = new QLineEdit("4", genBox);
    gspacer1 = new QSpacerItem(0,20);
    gspacer2 = new QSpacerItem(0,10);
    gspacer3 = new QSpacerItem(0,10);
    gspacer4 = new QSpacerItem(0,50);

    genBoxOverallLayout = new QVBoxLayout(genBoxWidget);
    functionLayout = new QVBoxLayout();
    colorwheelLayout = new QVBoxLayout();
    numtermsLayout = new QHBoxLayout();

    functionSel->addItem("Hex3");
    functionSel->addItem("Hex6");
    functionSel->addItem("Square");
    functionSel->addItem("Rhombic");
    functionSel->addItem("RhombicPaired");
    functionSel->addItem("Rectangular");
    functionSel->addItem("RectangularPaired");
    functionSel->addItem("General");
    functionSel->addItem("GeneralPaired");
    colorwheelSel->addItem("IcosColor");
    colorwheelSel->addItem("IcosColorC");
    colorwheelSel->addItem("StCol");
    colorwheelSel->addItem("StColC");
    colorwheelSel->addItem("StCol35");
    colorwheelSel->addItem("ZoneCol");
    colorwheelSel->addItem("SectCol");
    colorwheelSel->addItem("Sect6Col");
    colorwheelSel->addItem("WinCol");
    functionL->setText(tr("Function"));
    colorwheelL->setText(tr("Color Wheel"));
    numtermsE->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    numtermsL->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    colorwheelSel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    colorwheelL->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    functionSel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    functionL->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);



    numtermsE->setFixedWidth(30);
    numtermsE->setValidator(numtermsValidate);

    genBoxLayout = new QVBoxLayout(genBox);     //set up layout
    functionLayout->addWidget(functionL);
    functionLayout->addWidget(functionSel);
    numtermsLayout->addWidget(numtermsL);
    numtermsLayout->addWidget(numtermsE);
    functionLayout->addLayout(numtermsLayout);
    genBoxLayout->addLayout(functionLayout);
    genBoxLayout->addItem(gspacer1);
    colorwheelLayout->addItem(gspacer3);
    colorwheelLayout->addWidget(colorwheelL);
    colorwheelLayout->addWidget(colorwheelSel);
    genBoxLayout->addLayout(colorwheelLayout);
    genBoxLayout->addItem(gspacer2);

    genBoxOverallLayout->addWidget(genBox);
    genBoxOverallLayout->addItem(gspacer4);

    // PROPSBOX SUBELEMENTS
    outheightL = new QLabel(tr("Output Height"), propsBox);          //initialize elements
    outwidthL = new QLabel(tr("Output Width"), propsBox);
    XCornerL = new QLabel(tr("XCorner"), propsBox);
    YCornerL = new QLabel(tr("YCorner"), propsBox);
    worldwidthL = new QLabel(tr("World Width"), propsBox);
    worldheightL = new QLabel(tr("World Height"), propsBox);
    outheightE = new QLineEdit(propsBox);
    outwidthE = new QLineEdit(propsBox);
    XCornerE = new QLineEdit(propsBox);
    YCornerE = new QLineEdit(propsBox);
    worldwidthE = new QLineEdit(propsBox);
    worldheightE = new QLineEdit(propsBox);
    saveImagePush = new QPushButton(tr("Save Image"), propsBox);
    pspacer1 = new QSpacerItem(0, 12);
    pspacer2 = new QSpacerItem(0, 14);
    pspacer3 = new QSpacerItem(15, 30);
    pspacer4 = new QSpacerItem(20, 60);
    pspacer5 = new QSpacerItem(20, 15);

//    outheightE->setFixedWidth(100);
//    outwidthE->setFixedWidth(100);
//    XCornerE->setFixedWidth(100);
//    YCornerE->setFixedWidth(100);
//    worldwidthE->setFixedWidth(100);
//    worldheightE->setFixedWidth(100);

//    outheightE->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
//    outwidthE->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
//    XCornerE->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
//    YCornerE->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
//    worldwidthE->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
//    worldheightE->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);

    saveImagePush->setFixedHeight(25);
    propsBoxOverallLayout = new QVBoxLayout(propsBox);
    propsBoxLayout = new QHBoxLayout();
    propseditStack = new QVBoxLayout();
    propslabelStack = new QVBoxLayout();
    savePushLayout = new QHBoxLayout();

    outheightE->setValidator(dimValidate);
    outwidthE->setValidator(dimValidate);
    XCornerE->setValidator(doubleValidate);
    YCornerE->setValidator(doubleValidate);
    worldwidthE->setValidator(doubleValidate);
    worldheightE->setValidator(doubleValidate);

    outheightE->setFixedWidth(100);
    outwidthE->setFixedWidth(100);
    XCornerE->setFixedWidth(100);
    YCornerE->setFixedWidth(100);
    worldwidthE->setFixedWidth(100);
    worldheightE->setFixedWidth(100);

    saveImagePush->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    saveImagePush->setFixedWidth(150);

    propslabelStack->addWidget(XCornerL);
    propslabelStack->addWidget(YCornerL);
    propslabelStack->addWidget(worldwidthL);
    propslabelStack->addWidget(worldheightL);
    propslabelStack->addItem(pspacer1);
    propslabelStack->addWidget(outwidthL);
    propslabelStack->addWidget(outheightL);

    propslabelStack->setAlignment(XCornerL, Qt::AlignLeft);
    propslabelStack->setAlignment(YCornerL, Qt::AlignLeft);
    propslabelStack->setAlignment(worldwidthL, Qt::AlignLeft);
    propslabelStack->setAlignment(worldheightL, Qt::AlignLeft);
    propslabelStack->setAlignment(outwidthL, Qt::AlignLeft);
    propslabelStack->setAlignment(outheightL, Qt::AlignLeft);

    propseditStack->addWidget(XCornerE);
    propseditStack->addWidget(YCornerE);
    propseditStack->addWidget(worldwidthE);
    propseditStack->addWidget(worldheightE);
    propseditStack->addItem(pspacer2);
    propseditStack->addWidget(outwidthE);
    propseditStack->addWidget(outheightE);

    //propsBoxLayout->addItem(pspacer3);
    propsBoxLayout->addLayout(propslabelStack);
    propsBoxLayout->addLayout(propseditStack);
    propsBoxLayout->addItem(pspacer4);

    //savePushLayout->addWidget(saveImagePush);
    //savePushLayout->addItem(pspacer5);

    propsBoxOverallLayout->addLayout(propsBoxLayout);
    //propsBoxOverallLayout->addItem(pspacer3);
    propsBoxOverallLayout->addWidget(saveImagePush);
    propsBoxOverallLayout->setAlignment(saveImagePush, Qt::AlignRight);

    // DISP SUBELEMENTS
    disp = new Display(200, displayWidget);
    updatePreview = new QPushButton(tr("Update Preview"), this);
    dispLayout = new QVBoxLayout(displayWidget);
    dispLayout->addWidget(disp);
    dispLayout->addWidget(updatePreview);

    // CONNECT SIGNALS & SLOTS
    connect(updatePreview, SIGNAL(clicked()), this, SLOT(updatePreviewDisplay()));
    connect(colorwheelSel, SIGNAL(currentIndexChanged(int)), c, SLOT(setCurrent(int)));
    connect(functionSel, SIGNAL(currentIndexChanged(int)), this, SLOT(changeFunction(int)));
    connect(numtermsE, SIGNAL(textChanged(QString)), this, SLOT(changeMaxTerms(QString)));
    connect(currtermE, SIGNAL(valueChanged(int)), this, SLOT(updateTerms(int)));

    connect(outwidthE, SIGNAL(textChanged(QString)), this, SLOT(changeOWidth(QString)));
    connect(outheightE, SIGNAL(textChanged(QString)), this, SLOT(changeOHeight(QString)));
    connect(worldwidthE, SIGNAL(textChanged(QString)), this, SLOT(changeWorldWidth(QString)));
    connect(worldheightE, SIGNAL(textChanged(QString)), this, SLOT(changeWorldHeight(QString)));
    connect(XCornerE, SIGNAL(textChanged(QString)), this, SLOT(changeXCorner(QString)));
    connect(YCornerE, SIGNAL(textChanged(QString)), this, SLOT(changeYCorner(QString)));

    connect(nE, SIGNAL(textChanged(QString)), this, SLOT(changeN(QString)));
    connect(mE, SIGNAL(textChanged(QString)), this, SLOT(changeM(QString)));
    connect(rE, SIGNAL(textChanged(QString)), this, SLOT(changeR(QString)));
    connect(aE, SIGNAL(textChanged(QString)), this, SLOT(changeA(QString)));
    connect(scalerE, SIGNAL(textChanged(QString)), this, SLOT(changeScaleR(QString)));
    connect(scaleaE, SIGNAL(textChanged(QString)), this, SLOT(changeScaleA(QString)));

    connect(saveImagePush, SIGNAL(clicked()), this, SLOT(saveImageStart()));
    connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFunction()));
    connect(saveButton, SIGNAL(clicked()), this, SLOT(saveFunction()));

    // SET DEFAULTS
    refreshTerms();
    scalerE->setText(QString::number(f->scaleR()));
    scaleaE->setText(QString::number(f->scaleA()));

    outwidthE->setText(QString::number(settings::OWidth));
    outheightE->setText(QString::number(settings::OHeight));
    worldwidthE->setText(QString::number(settings::Width));
    worldheightE->setText(QString::number(settings::Height));
    XCornerE->setText(QString::number(settings::XCorner));
    YCornerE->setText(QString::number(settings::YCorner));

    functionSel->setCurrentIndex(0);    //set up current function
    colorwheelSel->setCurrentIndex(7);


    // FINALIZE WINDOW
    setFixedSize(sizeHint());
    setWindowTitle(tr("Wallpaper Generation"));
}