Skip to content

Commit

Permalink
Merge pull request #1 from timo0/master
Browse files Browse the repository at this point in the history
Thank to timo0:

    Add missing dependencies
    libMean now static and shared
    new UI for qtProgram
  • Loading branch information
madmas committed Jun 14, 2012
2 parents f2c5eca + 9603211 commit e2241d8
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 35 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ install_manifest.txt
*.so
*.a
Experiment

.DS*
.idea
Build
*.config
*.creator
*.files
*.includes
*.autosave
*.user
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ add_subdirectory(program)
add_subdirectory(qtProgram)

add_dependencies(Experiment mean)
add_dependencies(QtProgram means)
3 changes: 2 additions & 1 deletion libMean/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

add_library(mean STATIC mean.c)
add_library(means STATIC mean.c)
add_library(mean SHARED mean.c)
2 changes: 1 addition & 1 deletion program/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <stdio.h>
#include "mean.h"
#include <mean.h>

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion qtProgram/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ include_directories(../libMean)

add_executable(QtProgram ${qtProgram_SOURCES} ${qtProgram_HEADERS_MOC})

target_link_libraries(QtProgram mean ${QT_LIBRARIES})
target_link_libraries(QtProgram means ${QT_LIBRARIES})
70 changes: 45 additions & 25 deletions qtProgram/finddialog.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <QtGui>
#include <iostream>

extern "C" {
#include "mean.h"
Expand All @@ -10,57 +11,76 @@ extern "C" {
FindDialog::FindDialog(QWidget *parent)
: QDialog(parent)
{
label = new QLabel(tr("Find &what:"));
lineEdit = new QLineEdit;
label->setBuddy(lineEdit);
lineEditFirst = new QLineEdit;
labelFirst = new QLabel(tr("F&irst Number:"));
labelFirst->setBuddy(lineEditFirst);
connect(lineEditFirst, SIGNAL(textChanged(const QString &)),
this, SLOT(enableFindButton()));

caseCheckBox = new QCheckBox(tr("Match &case"));
backwardCheckBox = new QCheckBox(tr("Search &backward"));

findButton = new QPushButton(tr("&Find"));
findButton->setDefault(true);
findButton->setEnabled(false);
lineEditSecond = new QLineEdit;
labelSecond = new QLabel(tr("&Second Number:"));
labelSecond->setBuddy(lineEditSecond);
connect(lineEditSecond, SIGNAL(textChanged(const QString &)),
this, SLOT(enableFindButton()));

calcButton = new QPushButton(tr("&Calc"));
calcButton->setDefault(true);
calcButton->setEnabled(false);
connect(calcButton, SIGNAL(clicked()),
this, SLOT(findClicked()));

closeButton = new QPushButton(tr("Close"));

connect(lineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(enableFindButton(const QString &)));
connect(findButton, SIGNAL(clicked()),
this, SLOT(findClicked()));
connect(closeButton, SIGNAL(clicked()),
connect(closeButton, SIGNAL(clicked()),
this, SLOT(close()));

QHBoxLayout *topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(label);
topLeftLayout->addWidget(lineEdit);
topLeftLayout->addWidget(labelFirst);
topLeftLayout->addWidget(lineEditFirst);

QHBoxLayout *bottomleftLayout = new QHBoxLayout;
bottomleftLayout->addWidget(labelSecond);
bottomleftLayout->addWidget(lineEditSecond);

QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout);
leftLayout->addWidget(caseCheckBox);
leftLayout->addWidget(backwardCheckBox);
leftLayout->addLayout(bottomleftLayout);

QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(findButton);
rightLayout->addWidget(calcButton);
rightLayout->addWidget(closeButton);
rightLayout->addStretch();

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);

setLayout(mainLayout);
setWindowTitle(tr("Find"));
setWindowTitle(tr("Mean"));
setFixedHeight(sizeHint().height());
}

void FindDialog::enableFindButton(const QString &text)
void FindDialog::enableFindButton()
{
findButton->setEnabled(!text.isEmpty());
int length1 = lineEditFirst->text().length();
int length2 = lineEditSecond->text().length();

calcButton->setEnabled( length1 != 0 && length2 != 0 );
}

void FindDialog::findClicked()
{
QLabel *label = new QLabel(tr("not found. <br />But I've a number for you: %1").arg( mean(5,8) ));
label->show();
int a = atoi(lineEditFirst->text().toLocal8Bit().constData());
int b = atoi(lineEditSecond->text().toLocal8Bit().constData());

QString message = QString("The mean between %1 and %2 is %3").arg(a).arg(b).arg(mean(a,b));
QMessageBox box;

box.setWindowTitle("The Mean");
box.setText(message);

box.addButton(QMessageBox::Ok);
box.addButton(QMessageBox::Cancel);

box.exec();
}

12 changes: 6 additions & 6 deletions qtProgram/finddialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class FindDialog : public QDialog

private slots:
void findClicked();
void enableFindButton(const QString &text);
void enableFindButton();

private:
QLabel *label;
QLineEdit *lineEdit;
QCheckBox *caseCheckBox;
QCheckBox *backwardCheckBox;
QPushButton *findButton;
QLabel *labelFirst;
QLineEdit *lineEditFirst;
QLabel *labelSecond;
QLineEdit *lineEditSecond;
QPushButton *calcButton;
QPushButton *closeButton;
};

Expand Down

0 comments on commit e2241d8

Please sign in to comment.