MetronomeWindow::MetronomeWindow(MetronomeConf* conf)
{
	setupUi(this);

	this->statusBar()->showMessage("Stopped");

	timer = new QTimer(this);
	this->setTimerInterval();

	this->conf = conf;
	ticker = new Ticker( this->conf );

	this->tickIndex = 0;
	this->setAccents( this->accentsBox->value() );

	connect( this->timer, SIGNAL(timeout()), this, SLOT(doTick()) );
	connect( this->startStopTickingButton, SIGNAL(clicked()), this, SLOT(startStopTicking()) );
	connect( this->setBpmButton, SIGNAL(clicked()), this, SLOT(setBPM()) );
	connect( this->accentsBox, SIGNAL(valueChanged(int)), this, SLOT(setAccents(int)) );
	connect( this->quitAction, SIGNAL(triggered()), qApp, SLOT(quit()) );
	connect( this->aboutAction, SIGNAL(triggered()), this, SLOT(showAboutBox()) );

	connect( this->bpm60, SIGNAL(clicked()), this, SLOT(bpmPreset60()) );
	connect( this->bpm70, SIGNAL(clicked()), this, SLOT(bpmPreset70()) );
	connect( this->bpm80, SIGNAL(clicked()), this, SLOT(bpmPreset80()) );
	connect( this->bpm90, SIGNAL(clicked()), this, SLOT(bpmPreset90()) );
	connect( this->bpm100, SIGNAL(clicked()), this, SLOT(bpmPreset100()) );
	connect( this->bpm110, SIGNAL(clicked()), this, SLOT(bpmPreset110()) );
	connect( this->bpm120, SIGNAL(clicked()), this, SLOT(bpmPreset120()) );
}
Beispiel #2
0
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){
    ui->setupUi(this);
    connect(ui->cmdFetch,SIGNAL(clicked()),this,SLOT(fetch()));
    connect(ui->actionExit, SIGNAL(triggered()),this,SLOT(close()));
    connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAboutBox()));
    ui->statusBar->showMessage("Ready");
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    bridge(NULL),
    workerThread(NULL),
    debugListTimer(),
    debugListMessages()
{
    ui->setupUi(this);
    // Fixed width, minimum height
    this->setMinimumSize(this->size());
    this->setMaximumSize(this->size().width(), 2000);
#ifdef Q_OS_LINUX
    this->setWindowIcon(QIcon(":/images/images/icon48.png"));
#endif

    // Plumb event filter for focus events
    ui->cmbMidiIn->installEventFilter(this);
    ui->cmbMidiOut->installEventFilter(this);
    ui->cmbSerial->installEventFilter(this);

    // Load initial state
    this->workerThread = new QThread();
    this->workerThread->start(QThread::HighestPriority);
    refresh();
    scrollbackSize=Settings::getScrollbackSize();
    ui->chk_debug->setChecked( Settings::getDebug() );
    selectIfAvailable(ui->cmbMidiIn, Settings::getLastMidiIn());
    selectIfAvailable(ui->cmbMidiOut, Settings::getLastMidiOut());
    selectIfAvailable(ui->cmbSerial, Settings::getLastSerialPort());

    // Set up timer for the display list
    debugListTimer.setSingleShot(true);
    debugListTimer.setInterval(1000 / LIST_REFRESH_RATE);

    // Plumb signals & slots
    connect(ui->cmbMidiIn, SIGNAL(currentIndexChanged(int)), SLOT(onValueChanged()));
    connect(ui->cmbMidiOut, SIGNAL(currentIndexChanged(int)), SLOT(onValueChanged()));
    connect(ui->cmbSerial, SIGNAL(currentIndexChanged(int)), SLOT(onValueChanged()));
    connect(ui->chk_on, SIGNAL(clicked()), SLOT(onValueChanged()));
    connect(ui->chk_debug, SIGNAL(clicked(bool)), SLOT(onDebugClicked(bool)));
    connect(&debugListTimer, SIGNAL(timeout()), SLOT(refreshDebugList()));


    // Menu items
    connect(ui->actionExit, SIGNAL(triggered()), qApp, SLOT(quit()));
    connect(ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutBox()));
    connect(ui->actionPreferences, SIGNAL(triggered()), SLOT(showPreferences()));

    // Get started
    onValueChanged();

#ifdef Q_OS_MAC
    // hack: avoid an empty dummy File menu on OS X
    // there might be a better way to do this, but hide() and clear() don't work.
    ui->menuFile->setTitle(""); // Doesn't do anything on OS X
#endif

}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow){

    ui->setupUi(this);

    QMenu *helpMenu = new QMenu(tr("&Help"), this);
    QAction *aboutAction = helpMenu->addAction(tr("&About"));
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAboutBox()));
    ui->menuBar->addMenu(helpMenu);

    QStringList list;
    list << ConstStrings::number1;
    list << ConstStrings::number2;

    // Create a new model
    model = new QStandardItemModel(0,2,this);
    model->setHorizontalHeaderLabels(list);

    // Attach the model to the view
    ui->tableView->setModel(model);
    ui->tableView->setColumnWidth(0, 180);
    ui->tableView->setColumnWidth(1, 180);
    ui->tableView->resizeColumnsToContents();

    lbl = new QLabel("", this);
    progress = new QProgressBar(this);


    lblFrom = new QLabel(ConstStrings::from);
    ui->toolBar->addWidget(lblFrom);

    txtFrom = new QLineEdit(this);
    ui->toolBar->addWidget(txtFrom);
    txtFrom->setText(ConstStrings::one);

    lblTo = new QLabel(ConstStrings::to);
    ui->toolBar->addWidget(lblTo);

    txtTo = new QLineEdit(this);
    ui->toolBar->addWidget(txtTo);
    txtTo->setText(ConstStrings::fivemil);

    btnSearch = new QPushButton(ConstStrings::search, this);
    ui->toolBar->addWidget(btnSearch);

    connect(btnSearch, SIGNAL (released()),this, SLOT (released()));

    ui->statusBar->addPermanentWidget(lbl);
    ui->statusBar->addPermanentWidget(progress);
}
Beispiel #5
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    preferencesDialog = new PreferencesDialog();
    fontDialog = new FontDialog();
    errorMessage = new QErrorMessage();
    sheetNumberLabel = new QLabel("<h2>1</h2>");
    sheetNumberLabel->setToolTip(tr("Number of Current Sheet"));
    sheetNumberLabel->setFrameShape(QFrame::Panel);
    sheetNumberLabel->setFrameShadow(QFrame::Sunken);
    sheetNumberLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    sheetNumberLabel->setMinimumWidth(ui->toolBar->height());
    errorMessage->setMinimumSize(200, 150);

    //----File----
    connect(ui->actionConvert_to_Handwritten, SIGNAL(triggered()),
            this, SLOT(renderFirstSheet()));
    connect(ui->actionLoad_Text_from_File, SIGNAL(triggered()),
            this, SLOT(loadTextFromFile()));
    connect(ui->actionLoad_Font, SIGNAL(triggered()),
            this, SLOT(loadFont()));
    connect(ui->actionFont_Editor, SIGNAL(triggered()),
            fontDialog, SLOT(exec()));
    connect(ui->actionSave_Current_Sheet_as, SIGNAL(triggered()),
            this, SLOT(saveSheet()));
    connect(ui->actionSave_All_Sheets, SIGNAL(triggered()),
            this, SLOT(saveAllSheets()));
    connect(ui->actionPrint_Current_Sheet, SIGNAL(triggered()),
            this, SLOT(printSheet()));
    connect(ui->actionPrint_All, SIGNAL(triggered()),
            this, SLOT(printAllSheets()));

    //----Edit----
    //connect menu action "Show Toolbar"
    connect(ui->actionShow_ToolBar, SIGNAL(triggered(bool)),
            ui->toolBar, SLOT(setVisible(bool)));
    connect(ui->toolBar, SIGNAL(visibilityChanged(bool)),
            ui->actionShow_ToolBar, SLOT(setChecked(bool)));

    //preferencesDialog connections
    connect(ui->actionPreferences, SIGNAL(triggered()),
            preferencesDialog, SLOT(exec()));
    connect(preferencesDialog, SIGNAL(settingsChanged()),
            this, SLOT(loadSettings()));

    //----Help----
    connect(ui->actionAbout_Scribbler, SIGNAL(triggered()),
            this, SLOT(showAboutBox()));
    connect(ui->actionLicenses_and_Credits, SIGNAL(triggered()),
            this, SLOT(showLicensesBox()));
    connect(ui->actionHowTo, SIGNAL(triggered()),
            this, SLOT(showHowToBox()));

    //----ToolBar----
    //add actions to tool bar and connect them to slots
    connect(ui->toolBar->addAction(QPixmap("://render.png"), tr("Convert to Handwritten")), SIGNAL(triggered(bool)),
            this, SLOT(renderFirstSheet()));
    connect(ui->toolBar->addAction(QPixmap("://printer.png"), tr("Print Sheets")), SIGNAL(triggered(bool)),
            this, SLOT(printAllSheets()));
    connect(ui->toolBar->addAction(QPixmap("://save.png"), tr("Save Sheets")), SIGNAL(triggered(bool)),
            this, SLOT(saveAllSheets()));

    ui->toolBar->addSeparator();

    connect(ui->toolBar->addAction(QPixmap("://left.png"), tr("Previous Sheet")), SIGNAL(triggered(bool)),
            this, SLOT(renderPreviousSheet()));
    ui->toolBar->addWidget(sheetNumberLabel);
    connect(ui->toolBar->addAction(QPixmap("://right.png"), tr("Next Sheet")), SIGNAL(triggered(bool)),
            this, SLOT(renderNextSheet()));

    connect(fontDialog, SIGNAL(fontReady()),
            this, SLOT(updateCurrentSheet()));
    errorMessage->setModal(true);

    ui->toolBar->actions()[ToolButton::Render]->setShortcut(Qt::ControlModifier + Qt::Key_R);
    ui->toolBar->actions()[ToolButton::Print]->setShortcut(Qt::ControlModifier + Qt::Key_P);
    ui->toolBar->actions()[ToolButton::Save]->setShortcut(Qt::ControlModifier + Qt::Key_S);
    ui->toolBar->actions()[ToolButton::Next]->setShortcut(Qt::ControlModifier + Qt::Key_Right);
    ui->toolBar->actions()[ToolButton::Previous]->setShortcut(Qt::ControlModifier + Qt::Key_Left);
    ui->textEdit->installEventFilter(this);
    ui->toolBar->actions()[ToolButton::Next]->setDisabled(true);
    ui->toolBar->actions()[ToolButton::Previous]->setDisabled(true);

    //initialize some class members
    sheetPointers.push_back(0);
    currentSheetNumber = 0;

    preferencesDialog->loadSettingsFromFile();
    preferencesDialog->loadSettingsToFile();
}
Beispiel #6
0
/**
 * Callback function for the main window
 */
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
	int wmId, wmEvent;
	HDC hDc;
	COLORREF myColor = RGB(150,150,200);
	switch (message) {
	case WM_COMMAND:
		wmId    = LOWORD(wParam); 
		wmEvent = HIWORD(wParam); 
		switch (wmId) {

		//protocol combobox
		case ID_CBPROTOCOLS:

			//on combobox selection change
			if(wmEvent == CBN_SELCHANGE) {
				LRESULT selection = SendMessage(GetDlgItem(hWnd, ID_CBFUNCTIONS), CB_GETCURSEL, 0, 0);
				LRESULT dutProtocol = SendMessage(GetDlgItem(hWnd, ID_CBPROTOCOLS), CB_GETCURSEL, 0, 0);
				if(selection < 0)
					break;
				//set protocol for the function
				if(dutProtocol == -1)
					vapix->getFunction(selection)->setProtocol(vapix->getFunction(selection)->setProtocol(dutProtocol));
				else
					vapix->getFunction(selection)->setProtocol(dutProtocol);
				//emulate ID_EDIT_PORT EN_CHANGE message to update ID_EDIT_TOSEND text
				SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(ID_EDIT_PORT, EN_CHANGE), 0); 
			}
			break;

		//function combobox
		case ID_CBFUNCTIONS:

			//on combobox selection change
			if(wmEvent == CBN_SELCHANGE) {
				//clear the response edit box
				SetWindowText(GetDlgItem(hWnd, ID_EDIT_INFO), NULL);
				//reset dependent comboboxes
				SendMessage(GetDlgItem(hWnd, ID_CBPROTOCOLS), CB_RESETCONTENT, 0, 0);
				SendMessage(GetDlgItem(hWnd, ID_CBATTRIBUTE), CB_RESETCONTENT, 0, 0);
				SendMessage(GetDlgItem(hWnd, ID_CBVALUE), CB_RESETCONTENT, 0, 0);
				SendMessage(GetDlgItem(hWnd, ID_LBATTRIBUTES), LB_RESETCONTENT, 0, 0);
				//get selection index
				LRESULT selection = SendMessage(GetDlgItem(hWnd, ID_CBFUNCTIONS), CB_GETCURSEL, 0, 0);
				//set hostname/ip in the vapix object
				char* dutAddress = (char*)malloc(sizeof(char)*200);
				memset(dutAddress, '\0', 200);
				GetWindowText(GetDlgItem(hWnd, ID_EDIT_ADDRESS), dutAddress, 200);
				vapix->setHostname(dutAddress);
				//set port
				char* dutPort = (char*)malloc(sizeof(char)*6);
				memset(dutPort, '\0', 6);
				GetWindowText(GetDlgItem(hWnd, ID_EDIT_PORT), dutPort, 6);
				if(atoi(dutPort) > 0)
					vapix->setPort(selection, atoi(dutPort));
				else
					vapix->setPort(selection, atoi(vapix->getFunction(selection)->getProtocol()[1]));
				//remove attribute objects
				for(int i=0; i<VAPIX_FUNCTIONS_COUNT; i++) {
					vapix->getFunction(i)->removeAllAttributes();
				}
				//then get the function string and set it in the edit box
				SetWindowText(GetDlgItem(hWnd, ID_EDIT_TOSEND), vapix->getBrowserFunctionString(selection));
				//fill the protocols combobox
				int vpSize = 0;
				char*** validProtocols = vapix->getFunction(selection)->getValidProtocols(&vpSize);
				for(int i = 0; i<vpSize; i++) {
					SendMessage(GetDlgItem(hWnd, ID_CBPROTOCOLS), CB_ADDSTRING, 0, (LPARAM) validProtocols[i][0]);
				}
				//fill the attributes combobox with the vapix attributes for the selected function
				int vaSize = 0;
				VapixAttribute** vapixAttributes = vapix->getFunction(selection)->getValidAttributes(&vaSize);
				for(int i = 0; i<vaSize; i++) {
					SendMessage(GetDlgItem(hWnd, ID_CBATTRIBUTE), CB_ADDSTRING, 0, (LPARAM) vapixAttributes[i]->getName());
				}
				free(dutAddress);
				free(dutPort);
			}
			break;

		//attribute combobox
		case ID_CBATTRIBUTE:

			//on combobox selection change
			if(wmEvent == CBN_SELCHANGE) {
				//reset dependent comboboxes
				SendMessage(GetDlgItem(hWnd, ID_CBVALUE), CB_RESETCONTENT, 0, 0);
				//get selection index
				LRESULT selection = SendMessage(GetDlgItem(hWnd, ID_CBFUNCTIONS), CB_GETCURSEL, 0, 0);
				LRESULT selection2 = SendMessage(GetDlgItem(hWnd, ID_CBATTRIBUTE), CB_GETCURSEL, 0, 0);
				//fill the values combobox with the vapix values for the selected attribute in the selected function
				int vvSize = 0;
				char** vapixAttributeValues = vapix->getFunction(selection)->getValidAttribute(selection2)->getValidValues(&vvSize);
				for(int i = 0; i<vvSize; i++) {
					SendMessage(GetDlgItem(hWnd, ID_CBVALUE), CB_ADDSTRING, 0, (LPARAM) vapixAttributeValues[i]);
				}
				//update the "send" string
				SetWindowText(GetDlgItem(hWnd, ID_EDIT_TOSEND), vapix->getBrowserFunctionString(selection));
			}
			break;

		//add attribute button
		case ID_ATTRIBADD:
			addAttribute();
			break;
		//remove attribute button
		case ID_ATTRIBREMOVE:
			removeAttribute();
			break;
		case ID_EDIT_ADDRESS:
			if(wmEvent == EN_CHANGE) {
				char* dutAddress = (char*)malloc(sizeof(char)*200);
				memset(dutAddress, '\0', 200);
				GetWindowText(GetDlgItem(hWnd, ID_EDIT_ADDRESS), dutAddress, 200);
				vapix->setHostname(dutAddress);
				LRESULT selection = SendMessage(GetDlgItem(hWnd, ID_CBFUNCTIONS), CB_GETCURSEL, 0, 0);
				if(selection >= 0) {
					SetWindowText(GetDlgItem(hWnd, ID_EDIT_TOSEND), vapix->getBrowserFunctionString(selection));
				}
				free(dutAddress);
			}
			break;
		case ID_EDIT_PORT:
			if(wmEvent == EN_CHANGE) {
				LRESULT selection = SendMessage(GetDlgItem(hWnd, ID_CBFUNCTIONS), CB_GETCURSEL, 0, 0);
				if(selection < 0)
					break;
				char* dutPort = (char*)malloc(sizeof(char)*6);
				memset(dutPort, '\0', 6);
				GetWindowText(GetDlgItem(hWnd, ID_EDIT_PORT), dutPort, 6);
				//empty field means use protocol default port
				if(dutPort[0] == '\0')
					vapix->setPort(selection, atoi(vapix->getFunction(selection)->getProtocol()[1]));
				else
					vapix->setPort(selection, atoi(dutPort));
				SetWindowText(GetDlgItem(hWnd, ID_EDIT_TOSEND), vapix->getBrowserFunctionString(selection));
				free(dutPort);
			}
			break;
		case ID_SHOW_BUTTON:
			{
				//get selection index
				LRESULT selection = SendMessage(GetDlgItem(hWnd, ID_CBFUNCTIONS), CB_GETCURSEL, 0, 0);
				if(selection < 0) {
					MessageBox(hWnd, "A function must be selected before making a request!", "Info", MB_ICONEXCLAMATION);
					break;
				}

				//check if the function is returning text or binary
				int opener = vapix->getFunction(selection)->getOpener();
				switch(opener) {
				case 0:
					//open locally
					connectFunction(hWnd);
					break;
				case 1:
					//open in browser
					{
						char* temp = (char*)malloc(sizeof(char)*100);
						//get URI
						GetWindowText(GetDlgItem(hWnd, ID_EDIT_TOSEND), temp, 100);
						//open URI in the default browser
						openInBrowser(temp);
						free(temp);
					}
					break;
				case 2:
					//open in external video player (VLC)
					{
						//TODO: make it add user:password@ to URI
						char* temp = (char*)malloc(sizeof(char)*100);
						//get URI
						GetWindowText(GetDlgItem(hWnd, ID_EDIT_TOSEND), temp, 100);
						//open URI in VLC
						openInVLC(temp);
						free(temp);
					}
					break;
				default:
					{
						LRESULT selectedFunction = SendMessage(GetDlgItem(hWnd, ID_CBFUNCTIONS), CB_GETCURSEL, 0, 0);
						char* tmpStr = (char*)malloc(sizeof(char)*200);
						memset(tmpStr, '\0', 200);
						sprintf(tmpStr, "The selected function has an opener value (int VapixObject::VapixFunction::opener = %d)\nthat is not recognised by this version of Waapix(v%s).", vapix->getFunction(selectedFunction)->getOpener(), WAAPIX_VERSION);
						MessageBox(hWnd, tmpStr, "Error activating function", MB_ICONEXCLAMATION);
						free(tmpStr);
					}
				}
			}
			break;
		case ID_EXIT_BUTTON:
			DestroyWindow(hWnd);
			break;
		case IDM_ABOUT:
			showAboutBox(hWnd);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wmId, wmEvent);
		}
		break;
	case WM_DESTROY:
		WSACleanup();
		PostQuitMessage(0);
		break;
	case WM_CTLCOLORSTATIC:
		hDc = (HDC)(wParam); 
		SetBkMode(hDc, TRANSPARENT);
		return (INT_PTR)GetStockObject(NULL_BRUSH);
		break;
	case WM_SIZING:
		{
			RECT clientRect, *currentRect = (RECT*)lParam;
			BOOL processed = FALSE;
			GetClientRect(hWnd, &clientRect);
			if (currentRect->right - currentRect->left < MIN_WIDTH) {
				currentRect->right = currentRect->left + MIN_WIDTH;
				processed = TRUE;
			}
			if (currentRect->bottom - currentRect->top < MIN_HEIGHT) {
				currentRect->bottom = currentRect->top + MIN_HEIGHT;
				processed = TRUE;
			}
			if (processed) return TRUE;
		}
		break;
	case WM_SIZE:
		{
			RECT clientRect;
			GetClientRect(hWnd, &clientRect);
			SetWindowPos(GetDlgItem(hWnd, ID_EDIT_INFO), HWND_NOTOPMOST, 15, 272, clientRect.right-30, clientRect.bottom-272-15, SWP_NOZORDER);
		}
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Beispiel #7
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    preferencesDialog = new PreferencesDialog();
    fontDialog = new FontDialog();

    //----File----
    connect(ui->actionConvert_to_Handwritten, SIGNAL(triggered()),
            this, SLOT(renderFirstSheet()));
    connect(ui->actionLoad_Text_from_File, SIGNAL(triggered()),
            this, SLOT(loadTextFromFile()));
    connect(ui->actionLoad_Font, SIGNAL(triggered()),
            this, SLOT(loadFont()));
    connect(ui->actionFont_Editor, SIGNAL(triggered()),
            fontDialog, SLOT(exec()));
    connect(ui->actionSave_Current_Sheet_as, SIGNAL(triggered()),
            this, SLOT(saveSheet()));
    connect(ui->actionSave_All_Sheets, SIGNAL(triggered()),
            this, SLOT(saveAllSheets()));
    connect(ui->actionPrint_Current_Sheet, SIGNAL(triggered()),
            this, SLOT(printSheet()));
    connect(ui->actionPrint_All, SIGNAL(triggered()),
            this, SLOT(printAllSheets()));

    //----Edit----
    //connect menu action "Show Toolbar"
    connect(ui->actionShow_ToolBar, SIGNAL(triggered(bool)),
            ui->toolBar, SLOT(setVisible(bool)));
    connect(ui->toolBar, SIGNAL(visibilityChanged(bool)),
            ui->actionShow_ToolBar, SLOT(setChecked(bool)));

    //preferencesDialog connections
    connect(ui->actionPreferences, SIGNAL(triggered()),
            preferencesDialog, SLOT(exec()));
    connect(preferencesDialog, SIGNAL(settingsChanged()),
            ui->svgView, SLOT(loadSettingsFromFile()));

    //----Help----
    connect(ui->actionAbout_Scribbler, SIGNAL(triggered()),
            this, SLOT(showAboutBox()));
    connect(ui->actionLicenses_and_Credits, SIGNAL(triggered()),
            this, SLOT(showLicensesBox()));

    //----ToolBar----
    //add actions to tool bar and connect them to slots
    connect(ui->toolBar->addAction(QPixmap("://render.png"), tr("Convert to Handwritten")), SIGNAL(triggered(bool)),
            this, SLOT(renderFirstSheet()));
    connect(ui->toolBar->addAction(QPixmap("://printer.png"), tr("Print Current Sheet")), SIGNAL(triggered(bool)),
            this, SLOT(printSheet()));
    connect(ui->toolBar->addAction(QPixmap("://save.png"), tr("Save Current Sheet as Image")), SIGNAL(triggered(bool)),
            this, SLOT(saveSheet()));

    ui->toolBar->addSeparator();

    connect(ui->toolBar->addAction(QPixmap("://right.png"), tr("Next Sheet")), SIGNAL(triggered(bool)),
            this, SLOT(renderNextSheet()));
    connect(ui->toolBar->addAction(QPixmap("://left.png"), tr("Previous Sheet")), SIGNAL(triggered(bool)),
            this, SLOT(renderPreviousSheet()));

    connect(fontDialog, SIGNAL(fontReady()),
            ui->svgView, SLOT(loadFont()));

    ui->toolBar->actions()[4]->setDisabled(true);
    ui->toolBar->actions()[5]->setDisabled(true);

    //initialize some class members
    sheetPointers.push_back(0);
    currentSheetNumber = 0;
    version = "0.4 alpha";

    preferencesDialog->loadSettingsFromFile();

    /* This is a hack to avoid a bug. When program starts, it needs some time
     * (at least 1 ms on my configuration, but I set delay to 100 ms just to be sure
     * that it will work on weaker machines) before it can write settings to file,
     * otherwise ui->colorButton->palette().background().color() will return
     * default buttons background color, which will be written to settings
     * file at once program launches.
     */

    QTime dieTime = QTime::currentTime().addMSecs(100);
    while (QTime::currentTime() < dieTime)
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);

    preferencesDialog->loadSettingsToFile();
}
//! [0]
MainWindow::MainWindow()
{
//! [0]
    currentPath = QDir::homePath();
    model = new ImageModel(this);

    QWidget *centralWidget = new QWidget;

//! [1]
    view = new QTableView;
    view->setShowGrid(false);
    view->horizontalHeader()->hide();
    view->verticalHeader()->hide();
    view->horizontalHeader()->setMinimumSectionSize(1);
    view->verticalHeader()->setMinimumSectionSize(1);
    view->setModel(model);
//! [1]

//! [2]
    PixelDelegate *delegate = new PixelDelegate(this);
    view->setItemDelegate(delegate);
//! [2]

//! [3]
    QLabel *pixelSizeLabel = new QLabel(tr("Pixel size:"));
    QSpinBox *pixelSizeSpinBox = new QSpinBox;
    pixelSizeSpinBox->setMinimum(4);
    pixelSizeSpinBox->setMaximum(32);
    pixelSizeSpinBox->setValue(12);
//! [3]

    QMenu *fileMenu = new QMenu(tr("&File"), this);
    QAction *openAction = fileMenu->addAction(tr("&Open..."));
    openAction->setShortcuts(QKeySequence::Open);

    printAction = fileMenu->addAction(tr("&Print..."));
    printAction->setEnabled(false);
    printAction->setShortcut(QKeySequence::Print);

    QAction *quitAction = fileMenu->addAction(tr("E&xit"));
    quitAction->setShortcuts(QKeySequence::Quit);

    QMenu *helpMenu = new QMenu(tr("&Help"), this);
    QAction *aboutAction = helpMenu->addAction(tr("&About"));

    menuBar()->addMenu(fileMenu);
    menuBar()->addSeparator();
    menuBar()->addMenu(helpMenu);

    connect(openAction, SIGNAL(triggered()), this, SLOT(chooseImage()));
    connect(printAction, SIGNAL(triggered()), this, SLOT(printImage()));
    connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAboutBox()));
//! [4]
    connect(pixelSizeSpinBox, SIGNAL(valueChanged(int)),
            delegate, SLOT(setPixelSize(int)));
    connect(pixelSizeSpinBox, SIGNAL(valueChanged(int)),
            this, SLOT(updateView()));
//! [4]

    QHBoxLayout *controlsLayout = new QHBoxLayout;
    controlsLayout->addWidget(pixelSizeLabel);
    controlsLayout->addWidget(pixelSizeSpinBox);
    controlsLayout->addStretch(1);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(view);
    mainLayout->addLayout(controlsLayout);
    centralWidget->setLayout(mainLayout);

    setCentralWidget(centralWidget);

    setWindowTitle(tr("Pixelator"));
    resize(640, 480);
//! [5]
}
Beispiel #9
0
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
	setWindowTitle("Browzi");

	QMenu* fileMenu = menuBar()->addMenu(tr("&File"));
	fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence(Qt::ALT | Qt::Key_F4));
	QMenu* viewMenu = menuBar()->addMenu(tr("&View"));
	viewMenu->addAction(tr("&Font..."), this, SLOT(showFontDialog()));
	QActionGroup* pinyinGroup = new QActionGroup(this);
	pa = new QAction("Accented Pinyin",this);
	pa->setCheckable(true);
	pinyinGroup->addAction(pa);
	pn = new QAction("Numbered Pinyin",this);
	pn->setCheckable(true);
	pinyinGroup->addAction(pn);
	connect(pinyinGroup, SIGNAL(triggered(QAction*)), this, SLOT(pinyinDisplayChanged(QAction*)));
	viewMenu->addSeparator();
	viewMenu->addAction(pa);
	viewMenu->addAction(pn);

	QMenu* helpMenu = menuBar()->addMenu(tr("&Help"));
	helpMenu->addAction(tr("Visit &Website"), this, SLOT(goToWebsite()));
	helpMenu->addAction(tr("&About Browzi"), this, SLOT(showAboutBox()));

	// Holds all the sub-widgets
	QWidget* mainPanel = new QWidget(this);
	// hzLayout has the tabs in the left, the character display in the right
	QHBoxLayout* hzLayout = new QHBoxLayout(mainPanel);

	// Set up the search tab
	tabWidget = new QTabWidget(mainPanel);
	// Add tabs to the widget
	SearchRadical* searchByRadical = new SearchRadical(mainPanel);
	tabWidget->addTab(searchByRadical, QString("Radical"));
	SearchStrokeCount* searchByStrokeCount = new SearchStrokeCount();
	tabWidget->addTab(searchByStrokeCount, QString("Stroke Count"));
	SearchDraw* searchByDraw = new SearchDraw(tabWidget);
	tabWidget->addTab(searchByDraw, "Draw");
	SearchPinyin* searchPinyin = new SearchPinyin();
	tabWidget->addTab(searchPinyin, "Pinyin");
	SearchEnglish* searchEnglish = new SearchEnglish();
	tabWidget->addTab(searchEnglish, "English");
	Clipboard* clipboard = new Clipboard();
	tabWidget->addTab(clipboard, "Clipboard");

	hzLayout->addWidget(tabWidget);
	hzLayout->setStretchFactor(tabWidget, 2);

	// vtLayout contains the character panel, plus a spacer and about button
	QVBoxLayout* vtLayout = new QVBoxLayout();

	displayPanel = new CharacterDisplayPanel();
	vtLayout->addWidget(displayPanel);

	QSpacerItem* verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
	vtLayout->addItem(verticalSpacer);

	hzLayout->addLayout(vtLayout);
	hzLayout->setStretchFactor(vtLayout, 1);

	setCentralWidget(mainPanel);

	// Connect notifications
	connect(searchByRadical, SIGNAL(showCharacter(uint)), displayPanel, SLOT(setCharacter(uint)));
	connect(searchByStrokeCount, SIGNAL(showCharacter(uint)), displayPanel, SLOT(setCharacter(uint)));
	connect(searchByDraw, SIGNAL(showCharacter(uint)), displayPanel, SLOT(setCharacter(uint)));
	connect(searchPinyin, SIGNAL(showCharacter(uint)), displayPanel, SLOT(setCharacter(uint)));
	connect(searchEnglish, SIGNAL(showCharacter(uint)), displayPanel, SLOT(setCharacter(uint)));
	connect(clipboard, SIGNAL(showCharacter(uint)), displayPanel, SLOT(setCharacter(uint)));

	connect(this, SIGNAL(updateChineseFont(QFont)), searchByDraw, SLOT(setChineseFont(QFont)));
	connect(this, SIGNAL(updateChineseFont(QFont)), searchByRadical, SLOT(setChineseFont(QFont)));
	connect(this, SIGNAL(updateChineseFont(QFont)), searchByStrokeCount, SLOT(setChineseFont(QFont)));
	connect(this, SIGNAL(updateChineseFont(QFont)), searchPinyin, SLOT(setChineseFont(QFont)));
	connect(this, SIGNAL(updateChineseFont(QFont)), searchEnglish, SLOT(setChineseFont(QFont)));
	connect(this, SIGNAL(updateChineseFont(QFont)), clipboard, SLOT(setChineseFont(QFont)));
	connect(this, SIGNAL(updateChineseFont(QFont)), displayPanel, SLOT(setChineseFont(QFont)));

	connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));

	QSettings s("Browzi", "Browzi");
	setGeometry(QRect(s.value("pos", QPoint(200,100)).toPoint(), s.value("size",QSize(600,400)).toSize()));

	lastFont = QFont(s.value("font","unifont").toString(), 12);
	emit updateChineseFont(lastFont);

	PinyinConvertor::Mode m = PinyinConvertor::Mode(s.value("pinyin", 0).toInt());
	if(m == PinyinConvertor::PINYIN_ACCENTED) {
		pa->setChecked(true);
		PinyinConvertor::setAccented();
	}
	if(m == PinyinConvertor::PINYIN_NUMBERED) {
		pn->setChecked(true);
		PinyinConvertor::setNumbered();
	}
}