void Matrix::initGlobals() { setGeometry(0, 0, 500, 500); d_workspace = NULL; d_table_view = NULL; imageLabel = NULL; d_header_view_type = ColumnRow; d_color_map_type = Default; d_color_map = applicationWindow()->d_3D_color_map; d_column_width = 100; formula_str = ""; txt_format = 'f'; num_precision = 6; x_start = 1.0; x_end = 10.0; y_start = 1.0; y_end = 10.0; d_stack = new QStackedWidget(); d_stack->setFocusPolicy(Qt::StrongFocus); setWidget(d_stack); d_undo_stack = new QUndoStack(); d_undo_stack->setUndoLimit(applicationWindow()->matrixUndoStackSize()); }
void ToolBarPage::initDefaultViewToolBar() { clearToolbarActions(); if (MApplication::activeWindow()->isFullScreen() && !wasFullScreen) MApplication::activeWindow()->showNormal(); currentStyleName = defaultStyleName; if (!currentStyleName.isEmpty()) applicationWindow()->setStyleName(currentStyleName); applicationWindow()->setToolbarViewType(MToolBar::defaultType); }
void ToolBarPage::onAppear() { wasFullScreen = MApplication::activeWindow()->isFullScreen(); setBackButtonVisible(visibleBackButton->isChecked()); setMenuActionsVisible(visibleMenuButton->isChecked()); defaultStyleName = applicationWindow()->styleName(); if (!currentStyleName.isEmpty()) applicationWindow()->setStyleName(currentStyleName); if (isTabBarOnTop() && !MApplication::activeWindow()->isFullScreen()) MApplication::activeWindow()->showFullScreen(); }
bool ToolBarPage::isTabBarOnTop() { return ((applicationWindow()->toolbarViewType() == MToolBar::tabType) && (currentConfiguration == iconAndLabelTabsTop || currentConfiguration == iconTabsTop || currentConfiguration == textTabsTop)); }
void Matrix::initGlobals() { d_workspace = NULL; d_table_view = NULL; imageLabel = NULL; d_header_view_type = ColumnRow; d_color_map_type = GrayScale; d_color_map = QwtLinearColorMap(Qt::black, Qt::white); d_column_width = 100; formula_str = ""; txt_format = 'f'; num_precision = 6; x_start = 1.0; x_end = 10.0; y_start = 1.0; y_end = 10.0; d_stack = new QStackedWidget(); d_stack->setFocusPolicy(Qt::StrongFocus); setWidget(d_stack); d_undo_stack = new QUndoStack(); d_undo_stack->setUndoLimit(applicationWindow()->matrixUndoStackSize()); }
void MultiLayer::resizeLayers (QResizeEvent *re) { if (!d_scale_layers || applicationWindow()->d_opening_file) return; QSize oldSize = re->oldSize(); QSize size = re->size(); bool scaleLayerFonts = false; if(!oldSize.isValid()){// The old size is invalid when maximizing a window (why?) oldSize = QSize(canvas->childrenRect().width() + left_margin + right_margin, canvas->childrenRect().height() + top_margin + bottom_margin); scaleLayerFonts = true; } double w_ratio = (double)size.width()/(double)oldSize.width(); double h_ratio = (double)(size.height())/(double)(oldSize.height()); foreach (Graph *g, graphsList){ QObjectList lst = g->children(); foreach(QObject *o, lst){ if (o->isA("LegendWidget")) ((LegendWidget *)o)->setFixedCoordinatesMode(); } int gx = qRound(g->x()*w_ratio); int gy = qRound(g->y()*h_ratio); int gw = qRound(g->width()*w_ratio); int gh = qRound(g->height()*h_ratio); g->setGeometry(QRect(gx, gy, gw, gh)); if (scaleLayerFonts && g->autoscaleFonts()) g->scaleFonts(h_ratio); }
void Matrix::copySelection() { if (d_view_type == ImageView) return; QItemSelectionModel *selModel = d_table_view->selectionModel(); QString s = ""; QString eol = applicationWindow()->endOfLine(); if (!selModel->hasSelection()){ QModelIndex index = selModel->currentIndex(); s = text(index.row(), index.column()); } else { QItemSelection sel = selModel->selection(); QListIterator<QItemSelectionRange> it(sel); if(!it.hasNext()) return; QItemSelectionRange cur = it.next(); int top = cur.top(); int bottom = cur.bottom(); int left = cur.left(); int right = cur.right(); for(int i=top; i<=bottom; i++){ for(int j=left; j<right; j++) s += d_matrix_model->text(i, j) + "\t"; s += d_matrix_model->text(i,right) + eol; } } // Copy text into the clipboard QApplication::clipboard()->setText(s.trimmed()); }
bool Matrix::exportASCII(const QString& fname, const QString& separator, bool exportSelection) { QFile f(fname); if ( !f.open( QIODevice::WriteOnly ) ){ QApplication::restoreOverrideCursor(); QMessageBox::critical(this, tr("QtiPlot - ASCII Export Error"), tr("Could not write to file: <br><h4>%1</h4><p>Please verify that you have the right to write to this location!").arg(fname)); return false; } int rows = numRows(); int cols = numCols(); QTextStream t( &f ); QString eol = applicationWindow()->endOfLine(); if (exportSelection && d_view_type == TableView){ QModelIndexList selectedIndexes = d_table_view->selectionModel()->selectedIndexes(); int topRow = selectedIndexes[0].row(); int bottomRow = topRow; int leftCol = selectedIndexes[0].column(); int rightCol = leftCol; foreach(QModelIndex index, selectedIndexes){ int row = index.row(); if (row < topRow) topRow = row; if (row > bottomRow) bottomRow = row; int col = index.column(); if (col < leftCol) leftCol = col; if (col > rightCol) rightCol = col; }
void Matrix::setDefaultColorMap() { d_color_map_type = Default; d_color_map = applicationWindow()->d_3D_color_map; if (d_view_type == ImageView) displayImage(d_matrix_model->renderImage()); emit modifiedWindow(this); }
int Application::run() { QScopedPointer<QSplashScreen> splashScreen(buildSplashScreen()); splashScreen->showFullScreen(); QScopedPointer<QDeclarativeView> applicationWindow(buildRootView()); splashScreen->finish(applicationWindow.data()); applicationWindow->showFullScreen(); return QApplication::exec(); }
void ToolBarPage::onDisappear() { setBackButtonVisible(true); setMenuActionsVisible(true); applicationWindow()->setStyleName(defaultStyleName); MWindow *window = MApplication::activeWindow(); if (!wasFullScreen && window && window->isFullScreen()) window->showNormal(); }
void Matrix::invert() { if (numRows() != numCols()){ QMessageBox::critical((ApplicationWindow *)applicationWindow(), tr("QtiPlot - Error"), tr("Inversion failed, the matrix is not square!")); return; } if(d_matrix_model->initWorkspace()) d_undo_stack->push(new MatrixSymmetryOperation(d_matrix_model, Invert, tr("Invert"))); }
double Matrix::determinant() { int rows = numRows(); int cols = numCols(); if (rows != cols){ QMessageBox::critical((ApplicationWindow *)applicationWindow(), tr("QtiPlot - Error"), tr("Calculation failed, the matrix is not square!")); return GSL_POSINF; } gsl_set_error_handler_off(); gsl_matrix *A = gsl_matrix_alloc(rows, cols); gsl_permutation * p = gsl_permutation_alloc(rows); if (!A || !p){ QApplication::restoreOverrideCursor(); QMessageBox::critical((ApplicationWindow *)applicationWindow(), tr("QtiPlot") + " - " + tr("Memory Allocation Error"), tr("Not enough memory, operation aborted!")); return 0.0; } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); double *data = d_matrix_model->dataVector(); int i, cell = 0; for(i=0; i<rows; i++) for(int j=0; j<cols; j++) gsl_matrix_set(A, i, j, data[cell++]); gsl_linalg_LU_decomp(A, p, &i); double det = gsl_linalg_LU_det(A, i); gsl_matrix_free(A); gsl_permutation_free(p); QApplication::restoreOverrideCursor(); return det; }
void Matrix::print(const QString& fileName) { QPrinter printer; printer.setColorMode (QPrinter::GrayScale); if (!fileName.isEmpty()){ printer.setCreator("QtiPlot"); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); } else { QPrintDialog printDialog(&printer, applicationWindow()); if (printDialog.exec() != QDialog::Accepted) return; } printer.setFullPage( true ); print(&printer); }
/** * Make a widget floating or docked. * @param w :: A MdiSubWindow. It must be already detached from the tile and * ready to become floating or docked. * @param to :: A wrapper window option: Floating, Docked or Default. */ void TiledWindow::sendWidgetTo(MdiSubWindow *w, TiledWindow::RemoveDestination to) { w->resizeToDefault(); switch (to) { case (Floating): w->undock(); break; case (Docked): w->dock(); break; case (Default): default: if (applicationWindow()->isDefaultFloating(w)) { w->undock(); } else { w->dock(); } } }
void ToolBarPage::initTabViewToolBar(bool onTop, bool labels) { if (onTop) { currentStyleName = "CommonApplicationWindowTabBarOnTop"; if (!MApplication::activeWindow()->isFullScreen()) MApplication::activeWindow()->showFullScreen(); } else { if (MApplication::activeWindow()->isFullScreen() && !wasFullScreen) MApplication::activeWindow()->showNormal(); currentStyleName = labels ? "CommonApplicationWindow" : "CommonApplicationWindowTabBarLabelessIconTabs"; } currentStyleName = inv(currentStyleName); applicationWindow()->setStyleName(currentStyleName); clearToolbarActions(); ((MApplicationWindow*)MApplication::activeWindow())->setToolbarViewType(MToolBar::tabType); for (int i=1; i<=maxTabsSlider->value(); i++) addTab(i); }
void Matrix::print(const QString& fileName) { QPrinter printer; printer.setColorMode (QPrinter::GrayScale); if (!fileName.isEmpty()){ printer.setCreator("QtiPlot"); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); } else { QPrintDialog printDialog(&printer, applicationWindow()); if (printDialog.exec() != QDialog::Accepted) return; } printer.setFullPage( true ); QPainter p; if ( !p.begin(&printer ) ) return; // paint on printer int dpiy = printer.logicalDpiY(); const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins if (d_view_type == ImageView){ p.drawImage (printer.pageRect(), d_matrix_model->renderImage()); return; } QHeaderView *vHeader = d_table_view->verticalHeader(); int rows = numRows(); int cols = numCols(); int height = margin; int i, vertHeaderWidth = vHeader->width(); int right = margin + vertHeaderWidth; // print header p.setFont(QFont()); QString header_label = d_matrix_model->headerData(0, Qt::Horizontal).toString(); QRect br = p.boundingRect(br, Qt::AlignCenter, header_label); p.drawLine(right, height, right, height+br.height()); QRect tr(br); for(i=0; i<cols; i++){ int w = d_table_view->columnWidth(i); tr.setTopLeft(QPoint(right,height)); tr.setWidth(w); tr.setHeight(br.height()); header_label = d_matrix_model->headerData(i, Qt::Horizontal).toString(); p.drawText(tr, Qt::AlignCenter, header_label,-1); right += w; p.drawLine(right, height, right, height+tr.height()); if (right >= printer.width()-2*margin ) break; } p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line height += tr.height(); p.drawLine(margin, height, right-1, height); // print table values for(i=0;i<rows;i++){ right = margin; QString cell_text = d_matrix_model->headerData(i, Qt::Horizontal).toString()+"\t"; tr = p.boundingRect(tr, Qt::AlignCenter, cell_text); p.drawLine(right, height, right, height+tr.height()); br.setTopLeft(QPoint(right,height)); br.setWidth(vertHeaderWidth); br.setHeight(tr.height()); p.drawText(br,Qt::AlignCenter,cell_text,-1); right += vertHeaderWidth; p.drawLine(right, height, right, height+tr.height()); for(int j=0; j<cols; j++){ int w = d_table_view->columnWidth (j); cell_text = text(i,j)+"\t"; tr = p.boundingRect(tr,Qt::AlignCenter,cell_text); br.setTopLeft(QPoint(right,height)); br.setWidth(w); br.setHeight(tr.height()); p.drawText(br, Qt::AlignCenter, cell_text, -1); right += w; p.drawLine(right, height, right, height+tr.height()); if (right >= printer.width()-2*margin ) break; } height += br.height(); p.drawLine(margin, height, right-1, height); if (height >= printer.height()-margin ){ printer.newPage(); height = margin; p.drawLine(margin, height, right, height); } } }
void Matrix::pasteSelection() { if (d_view_type == ImageView) return; QString text = QApplication::clipboard()->text(); if (text.isEmpty()) return; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QStringList linesList = text.split(applicationWindow()->endOfLine(), QString::SkipEmptyParts); int rows = linesList.size(); if (!rows) return; int cols = linesList[0].split("\t").count(); for (int i = 1; i < rows; i++){ int aux = linesList[i].split("\t").count(); if (aux > cols) cols = aux; } int topRow = 0, leftCol = 0; QItemSelectionModel *selModel = d_table_view->selectionModel(); if (selModel->hasSelection()){ QItemSelectionRange sel = selModel->selection()[0]; topRow = sel.top(); leftCol = sel.left(); } int oldRows = numRows(); int bottomRow = topRow + rows - 1; if (bottomRow > oldRows - 1) bottomRow = oldRows - 1; int oldCols = numCols(); int rightCol = leftCol + cols - 1; if (rightCol > oldCols - 1) rightCol = oldCols - 1; double *clipboardBuffer = (double *)malloc(rows*cols*sizeof(double)); if (!clipboardBuffer){ QMessageBox::critical(this, tr("QtiPlot") + " - " + tr("Memory Allocation Error"), tr("Not enough memory, operation aborted!")); QApplication::restoreOverrideCursor(); return; } QLocale locale = this->locale(); //Better use QLocale::system() ?? int cell = 0; for(int i = 0; i < rows; i++){ QStringList cells = linesList[i].split("\t"); int size = cells.count(); for(int j = 0; j<cols; j++){ if (j >= size){ clipboardBuffer[cell++] = GSL_NAN; continue; } bool numeric = true; double value = locale.toDouble(cells[j], &numeric); if (numeric) clipboardBuffer[cell++] = value; else clipboardBuffer[cell++] = GSL_NAN; } } QApplication::restoreOverrideCursor(); double *backupBuffer = d_matrix_model->dataCopy(topRow, bottomRow, leftCol, rightCol); if (backupBuffer){ d_undo_stack->push(new MatrixPasteCommand(d_matrix_model, topRow, bottomRow, leftCol, rightCol, clipboardBuffer, rows, cols, backupBuffer, oldRows, oldCols, tr("Paste"))); emit modifiedWindow(this); } else if (ignoreUndo()){ d_matrix_model->pasteData(clipboardBuffer, topRow, leftCol, rows, cols); emit modifiedWindow(this); } }
void ArtistPage::createContent() { MApplicationPage::createContent(); QGraphicsWidget *panel = centralWidget(); MLayout* layout = new MLayout(panel); m_policy = new MLinearLayoutPolicy(layout, Qt::Vertical); layout->setAnimation(NULL); panel->setLayout(layout); layout->setLandscapePolicy(m_policy); layout->setPortraitPolicy(m_policy); if (m_pageMode == ALL_ARTISTS) { // Menu Actions MAction* actionImportLastfm = new MAction(panel); actionImportLastfm->setText(tr("Import from Last.fm")); actionImportLastfm->setLocation(MAction::ApplicationMenuLocation); addAction(actionImportLastfm); connect(actionImportLastfm, SIGNAL(triggered()), this, SLOT(slotImportLastfm())); MAction* actionAddArtist = new MAction(panel); actionAddArtist->setText(tr("Add artist")); actionAddArtist->setLocation(MAction::ApplicationMenuLocation); addAction(actionAddArtist); connect(actionAddArtist, SIGNAL(triggered()), this, SLOT(slotAddArtist())); // Toolbar Actions MAction* actionFilter = new MAction("icon-m-toolbar-filter", "", this); actionFilter->setLocation(MAction::ToolBarLocation); addAction(actionFilter); connect(actionFilter, SIGNAL(triggered()), this, SLOT(slotShowFilter())); } MAction* actionRefresh = new MAction("icon-m-toolbar-refresh", "", this); actionRefresh->setLocation(MAction::ToolBarLocation); addAction(actionRefresh); connect(actionRefresh, SIGNAL(triggered()), this, SLOT(slotRefreshEvents())); MAction* actionSearch = new MAction("icon-m-toolbar-search", "", this); actionSearch->setLocation(MAction::ToolBarLocation); addAction(actionSearch); connect(actionSearch, SIGNAL(triggered()), this, SLOT(slotShowSearch())); // setup model m_artistsModel = new ArtistModel(m_dbStorage, artistsModelQuery()); // filtering text box QGraphicsLinearLayout *containerLayout = new QGraphicsLinearLayout(Qt::Horizontal); MLabel* filterLabel = new MLabel(tr("Filter artist:")); containerLayout->addItem(filterLabel); m_filter = new MTextEdit(MTextEditModel::SingleLine, QString()); containerLayout->addItem(m_filter); m_filter->setObjectName("CommonSingleInputField"); connect(m_filter, SIGNAL(textChanged()), this, SLOT(slotFilterChanged())); m_filterWidget = new MWidget(); m_filterWidget->setLayout(containerLayout); // No artist found label m_noArtistLabel = new MLabel(tr("No artist available, add them using one of " "menu options.")); m_noArtistLabel->setAlignment(Qt::AlignCenter); if (m_artistsModel->rowCount() == 0) m_policy->addItem(m_noArtistLabel); // MList with fast view MList* artistsList = new MList(); artistsList->setSelectionMode(MList::SingleSelection); // Content item creator and item model for the list artistsList->setCellCreator(new ArtistItemCreator(m_pageMode, m_dbStorage, m_country)); artistsList->setItemModel(m_artistsModel); m_policy->addItem(artistsList); connect(artistsList, SIGNAL(itemClicked(QModelIndex)), this, SLOT(slotArtistClicked(QModelIndex))); connect(DBManager::instance(m_dbStorage), SIGNAL(artistAdded(int,bool)), this, SLOT(slotArtistAdded(int,bool))); if (m_pageMode == ARTIST_NEAR_LOCATION_SEARCH) { //overwrite history MApplicationWindow* appWindow = applicationWindow(); MScene* scene = appWindow->scene(); MSceneManager* sceneManager = scene->sceneManager(); QList<MSceneWindow*> history = sceneManager->pageHistory(); if (history.last()->metaObject()->className() == NearLocationSearchPage::staticMetaObject.className()) { // overwrite history only if the last page is NearLocationSearchPage history.removeAt(history.size()-1); if (history.last()->metaObject()->className() != NearLocationMainPage::staticMetaObject.className()) { MApplicationPage* prevPage = new NearLocationMainPage(); history << prevPage; } sceneManager->setPageHistory(history); } //search events m_lastfm->getEventsNearLocation(m_latitude, m_longitude, m_distance); } if (m_dbStorage == DBManager::DISK) { DBManager* db = DBManager::instance(m_dbStorage); QStringList incompleteArtists = db->incompleteArtists(); foreach(QString artist, incompleteArtists) { m_lastfm->getEventsForArtist(artist); }