void insertTime(CTEditBase *e) { char buf[32]; int i=insertTime(&buf[0]); e->addText(buf,i); }
double computeMFLOPS(const dvector_t & tim, const double mflo, Tag::TimeSelect ts ) { linbox_check(tim.size()); switch (ts) { case (Tag::TimeSelect::average) : { double tps = 0 ; for (size_t i = 0 ; i < tim.size() ; ++i) tps += tim[i] ; return computeMFLOPS(tps,mflo,(size_t)tim.size()); } case (Tag::TimeSelect::bestThree) : { if (tim.size() <4) return computeMFLOPS(tim,mflo,Tag::TimeSelect::average); dvector_t tps (3); double t1,t2 ; if (tim[0]<tim[1]) { t1 = tim[0]; t2 = tim[1]; } else { t1 = tim[1]; t2 = tim[0]; } if (tim[3] < t1) { tps[0] = tim[3] ; tps[1] = t1 ; tps[2] = t2 ; } else if (tim[2] < t1) { tps[0] = t1 ; tps[1] = tim[3] ; tps[2] = t2 ; } else { tps[0] = t1 ; tps[1] = t2; tps[2] = tim[3] ; } for (size_t i = 3 ; i < tim.size() ; ++i) insertTime(tps,tim[i]); return computeMFLOPS(tim,mflo,Tag::TimeSelect::average); } case (Tag::TimeSelect::bestOne) : { double t1 = tim[0] ; for (size_t i = 1 ; i < tim.size() ; ++i) if (tim[i] < t1) t1 = tim[i] ; return computeMFLOPS(t1,mflo,1); } case (Tag::TimeSelect::median) : { if (tim.size() == 1) return computeMFLOPS(tim[0],mflo,1) ; dvector_t tps (tim); std::sort(tps.begin(),tps.end()); size_t mid = (size_t)tps.size()/2 ; double t1 ; if (isOdd((uint64_t)tps.size())) t1 = tps[mid] ; else t1 = (tps[mid-1]+tps[mid])/2; return computeMFLOPS(t1,mflo,1); } case (Tag::TimeSelect::medmean) : { if (tim.size() < 3) return computeMFLOPS(tim,mflo,Tag::TimeSelect::median); ; size_t q1 = (size_t)((double)tim.size()/(double)4) ; size_t q3 = (size_t)tim.size()-q1 ; dvector_t tps (tim); std::sort(tps.begin(),tps.end()); dvector_t tps2 (tim.begin()+q1,tim.begin()+q3); return computeMFLOPS(tps2,mflo,Tag::TimeSelect::average); } default : { throw("not among tags"); } } // switch(ts) }
TextRoom::TextRoom(QWidget *parent, Qt::WFlags f) : QWidget(parent, f), sentenceTally(0) { setupUi(this); setObjectName("textroom"); // Set the default values for variables. numChanges = 0; prevLength = 0; wordcount = 0; alarm = 0; parasold = 0; isHighlighted = false; #ifdef Q_OS_MACX // Find the path for the app path QDir tmpDir = QDir(QCoreApplication::applicationDirPath()); // go into Resources folder tmpDir.cdUp(); tmpDir.cd("Resources"); // get the full path for the resources resourcesDir = tmpDir.path(); #endif // Create the dialog windows. optionsDialog = new OptionsDialog(this); helpDialog = new HelpDialog(this); selectFont = new SelectFont(this); aboutDialog = new AboutDialog(this); scratchDialog = new ScratchDialog(this); miniFlo = new MiniFlo(this); getAWord = new GetAWord(this); musicRoom = new MusicRoom(this); googleDocsDialog = new GoogleDocsDialog(this); // Read settings saved by Options Dialog. #ifdef Q_OS_WIN32 settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::applicationName()); #else settings = new QSettings(); #endif readSettings(); // Sound adjustments. int audio_rate = 11025; Uint16 audio_format = AUDIO_S16SYS; int audio_channels = 2; int audio_buffers = 1024; if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) { printf("Unable to initialize audio: %s\n", Mix_GetError()); exit(1); } // Load sounds. #ifdef Q_OS_WIN32 soundenter = Mix_LoadWAV("keyenter.wav"); #elif defined(Q_OS_MACX) QString tmp = resourcesDir; tmp.append("/sounds/keyenter.wav"); soundenter = Mix_LoadWAV(tmp.toAscii()); #else soundenter = Mix_LoadWAV("/usr/share/sounds/keyenter.wav"); #endif if(soundenter == NULL) { printf("Unable to load WAV file: %s\n", Mix_GetError()); } #ifdef Q_OS_WIN32 soundany = Mix_LoadWAV("keyany.wav"); #elif defined(Q_OS_MACX) tmp = resourcesDir; tmp.append("/sounds/keyany.wav"); soundany = Mix_LoadWAV(tmp.toAscii()); #else soundany = Mix_LoadWAV("/usr/share/sounds/keyany.wav"); #endif if(soundany == NULL) { printf("Unable to load WAV file: %s\n", Mix_GetError()); } // Create the keyboard shortcuts. new QShortcut ( QKeySequence(QKeySequence::New), this, SLOT( newFile() ) ); new QShortcut ( QKeySequence(QKeySequence::Open), this, SLOT( open() ) ); new QShortcut ( QKeySequence(QKeySequence::Save), this, SLOT( save() ) ); new QShortcut ( QKeySequence(QKeySequence::HelpContents), this, SLOT( help() ) ); #ifdef Q_OS_MACX new QShortcut ( QKeySequence(tr("F1", "Help")), this, SLOT( help() ) ); #endif new QShortcut ( QKeySequence(tr("F2", "Options")), this, SLOT( options() ) ); new QShortcut ( QKeySequence(tr("F3", "About")), this, SLOT( about() ) ); new QShortcut ( QKeySequence(tr("F5", "Spell Check")), this, SLOT( spellCheck() ) ); new QShortcut ( QKeySequence(tr("F6", "Scratch Pad")), this, SLOT( showScratchPad() ) ); new QShortcut ( QKeySequence(tr("Ctrl+P", "Print")), this, SLOT( print() ) ); new QShortcut ( QKeySequence(tr("Shift+Ctrl+S", "Save As")), this, SLOT( saveAs() ) ); new QShortcut ( QKeySequence(tr("Ctrl+D", "Insert Date")), this, SLOT( insertDate() ) ); new QShortcut ( QKeySequence(tr("Ctrl+T", "Insert Time")), this, SLOT( insertTime() ) ); new QShortcut ( QKeySequence(tr("Ctrl+Q", "Quit Application")) , this, SLOT( close() ) ); new QShortcut ( QKeySequence(tr("Alt+F4", "Quit Application")) , this, SLOT( close() ) ); new QShortcut ( QKeySequence(tr("Ctrl+F", "Find Text")) , this, SLOT( find() ) ); new QShortcut ( QKeySequence(tr("F11", "Toggle Fullscreen")) , this, SLOT( toggleFullScreen() ) ); new QShortcut ( QKeySequence(tr("Esc", "Toggle Fullscreen")) , this, SLOT( toggleEscape() ) ); new QShortcut ( QKeySequence(tr("Ctrl+M", "Minimize TextRoom")) , this, SLOT( showMinimized() ) ); new QShortcut ( QKeySequence(tr("F4", "Find Next")) , this, SLOT( find_next() ) ); new QShortcut ( QKeySequence(tr("Ctrl+F4", "Find Previous")) , this, SLOT( find_previous() ) ); new QShortcut ( QKeySequence(tr("Ctrl+B", "Bold")) , this, SLOT( textBold() ) ); new QShortcut ( QKeySequence(tr("Ctrl+I", "Italic")) , this, SLOT( textItalic() ) ); new QShortcut ( QKeySequence(tr("Ctrl+Up", "Increase Text Size")) , this, SLOT( textSizeUp() ) ); new QShortcut ( QKeySequence(tr("Ctrl+Down", "Decrease Text Size")) , this, SLOT( textSizeDown() ) ); new QShortcut ( QKeySequence(tr("Ctrl+W", "Select Font")) , this, SLOT( changeFont() ) ); new QShortcut ( QKeySequence(tr("Ctrl+R", "Align Right")) , this, SLOT( alignRight() ) ); new QShortcut ( QKeySequence(tr("Ctrl+L", "Align Left")) , this, SLOT( alignLeft() ) ); new QShortcut ( QKeySequence(tr("Ctrl+J", "Align Justify")) , this, SLOT( alignJustify() ) ); new QShortcut ( QKeySequence(tr("Ctrl+E", "Align Center")) , this, SLOT( alignCenter() ) ); new QShortcut ( QKeySequence(tr("Ctrl+Alt+I", "Insert Image")) , this, SLOT( insertImage() ) ); new QShortcut ( QKeySequence(tr("F7", "Show MiniFlo")) , this, SLOT( showMiniFlo() ) ); new QShortcut ( QKeySequence(tr("F8", "Get A Word")) , this, SLOT( showGetAWord() ) ); new QShortcut ( QKeySequence(tr("F9", "MusicRoom")) , this, SLOT( showMusicRoom() ) ); new QShortcut ( QKeySequence(tr("F10", "Google Docs")) , this, SLOT( exportToGoogle() ) ); // Service: show cursor new QShortcut ( QKeySequence(tr("Shift+F4", "Show Cursor")) , this, SLOT( sCursor() ) ); //fw = new QFileSystemWatcher(this); //fw->addPath( settings->fileName() ); // If file is changed, read the settings-> //connect(fw, SIGNAL(fileChanged(const QString)), // this, SLOT(readSettings())); // If the document is changed, do some stuff. connect(textEdit->document(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified())); // If position is changed, scroll. connect(textEdit->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(vPositionChanged())); // If horizontal scrollar is changed, scroll. connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(hSliderPositionChanged())); connect(textEdit, SIGNAL(anchorClicked(QUrl)), this, SLOT(showScratchPad())); // check if we need to open some file at startup const QStringList args = QCoreApplication::arguments(); if (args.count() == 2) { QFile file( args.at(1) ); if ( file.exists() ) curFile = args.at(1); } if (!curFile.isEmpty()) loadFile(curFile); else newFile(); // set cursor position if ( isSaveCursor ) { textEdit->textCursor().setPosition(cPosition); } writeSettings(); // Refresh the file status every second. QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(getFileStatus())); timer->start(1000); }