// Send a "Set font" event to the GUI, and wait for the font metrics answer void qt_sendFont() { qt->out << GESetFont << qt->currentFontName << qt->currentFontSize; QPair<QString, int> currentFont(qt->currentFontName, qt->currentFontSize); static QPair<QString, int> lastFont("", 0); // The font has not changed if (currentFont == lastFont) return; static QMap<QPair<QString, int>, QPair<int, int> > fontMetricCache; QPair<int, int> metric; // Try to find the font metric in the cache or ask the GUI for the font metrics if (fontMetricCache.contains(currentFont)) metric = fontMetricCache[currentFont]; else { qt->out << GEFontMetricRequest; qt_flushOutBuffer(); bool receivedFontProps = false; int waitcount = 0; while (!receivedFontProps) { qt->socket.waitForReadyRead(1000); if (qt->socket.bytesAvailable() < (int)sizeof(gp_event_t)) { fprintf(stderr, (waitcount++ % 10 > 0) ? " ." : "\nWarning: slow font initialization"); #ifdef Q_OS_MAC // OSX can be slow (>30 seconds?!) in determining font metrics // Give it more time rather than failing after 1 second // Possibly this is only relevant to Qt5 GP_SLEEP(0.5); continue; #endif return; } while (qt->socket.bytesAvailable() >= (int)sizeof(gp_event_t)) { gp_event_t event; qt->socket.read((char*) &event, sizeof(gp_event_t)); // Here, we discard other events than fontprops. if ((event.type == GE_fontprops) && (event.par1 > 0) && (event.par2 > 0)) { receivedFontProps = true; metric = QPair<int, int>(event.par1, event.par2); fontMetricCache[currentFont] = metric; break; } } } if (waitcount > 0) fprintf(stderr,"\n"); } term->v_char = qt_oversampling*metric.first; term->h_char = qt_oversampling*metric.second; lastFont = currentFont; }
void qt_set_cursor(int c, int x, int y) { // Cancel zoombox when Echap is pressed if (c == 0) qt_out << GEZoomStop << QString(); if (c == -4) qt_out << GELineTo << false; else if (c == -3) qt_out << GELineTo << true; else if (c == -2) // warp the pointer to the given position qt_out << GEWrapCursor << qt_termCoord(x, y); else if (c == -1) // start zooming qt_out << GECursor << Qt::SizeFDiagCursor; else if (c == 1) // Rotation qt_out << GECursor << Qt::ClosedHandCursor; else if (c == 2) // Rescale qt_out << GECursor << Qt::SizeAllCursor; else if (c == 3) // Zoom qt_out << GECursor << Qt::SizeFDiagCursor; else qt_out << GECursor << Qt::CrossCursor; qt_flushOutBuffer(); }
// Called after plotting is done void qt_text() { if (qt_optionRaise) qt_out << GERaise; qt_out << GEDone; qt_flushOutBuffer(); }
void qt_atexit() { if (qt_optionPersist || persist_cl) qt_out << GEPersist; else qt_out << GEExit; qt_flushOutBuffer(); qt_initialized = false; }
// Display temporary text, after // erasing any temporary text displayed previously at this location. // The int determines where: 0=statusline, 1,2: at corners of zoom // box, with \r separating text above and below the point. void qt_put_tmptext(int n, const char str[]) { if (n == 0) qt_out << GEStatusText << QString(str); else if (n == 1) qt_out << GEZoomStart << QString(str); else if (n == 2) qt_out << GEZoomStop << QString(str); qt_flushOutBuffer(); }
// Called after plotting is done void qt_text() { if (qt_optionRaise) { #ifdef _WIN32 // The qt graph window is in another process and we must explicitly allow it to "raise". AllowSetForegroundWindow(qt->pid); #endif qt->out << GERaise; } qt->out << GEDone; qt_flushOutBuffer(); }
// Called just before a plot is going to be displayed. void qt_graphics() { ensureOptionsCreated(); qt->out << GEDesactivate; qt_flushOutBuffer(); qt_connectToServer(); // Set text encoding if (!(qt->codec = qt_encodingToCodec(encoding))) qt->codec = QTextCodec::codecForLocale(); // Set font qt->currentFontSize = qt_optionFontSize; qt->currentFontName = qt_option->FontName; // Set plot size if (qt_setSize) { term->xmax = qt_oversampling*qt_setWidth; term->ymax = qt_oversampling*qt_setHeight; qt_setSize = false; } // Initialize window qt->out << GESetCurrentWindow << qt_optionWindowId; qt->out << GEInitWindow; #ifdef _WIN32 // Let the terminal window know our PID qt->out << GEPID << quint32(GetCurrentProcessId()); #endif qt->out << GEActivate; qt->out << GETitle << qt_option->Title; qt->out << GESetCtrl << qt_optionCtrl; qt->out << GESetWidgetSize << QSize(term->xmax, term->ymax)/qt_oversampling; // Initialize the scene qt->out << GESetSceneSize << QSize(term->xmax, term->ymax)/qt_oversampling; qt->out << GEClear; // Initialize the font qt_sendFont(); term->v_tic = (unsigned int) (term->v_char/2.5); term->h_tic = (unsigned int) (term->v_char/2.5); if (qt_setPosition) { qt->out << GESetPosition << qt_option->position; qt_setPosition = false; } }
// Called just before a plot is going to be displayed. void qt_graphics() { ensureOptionsCreated(); qt->out << GEDesactivate; qt_flushOutBuffer(); qt_connectToServer(); // Set text encoding if (!(qt->codec = qt_encodingToCodec(encoding))) qt->codec = QTextCodec::codecForLocale(); // Set font qt->currentFontSize = qt_optionFontSize; qt->currentFontName = qt_option->FontName; // Set plot metrics QFontMetrics metrics(QFont(qt->currentFontName, qt->currentFontSize)); term->v_char = qt_oversampling * (metrics.ascent() + metrics.descent()); term->h_char = qt_oversampling * metrics.width("0123456789")/10.; term->v_tic = (unsigned int) (term->v_char/2.5); term->h_tic = (unsigned int) (term->v_char/2.5); if (qt_setSize) { term->xmax = qt_oversampling*qt_setWidth; term->ymax = qt_oversampling*qt_setHeight; qt_setSize = false; } // Initialize window qt->out << GESetCurrentWindow << qt_optionWindowId; qt->out << GEInitWindow; qt->out << GEActivate; qt->out << GETitle << qt_option->Title; qt->out << GESetCtrl << qt_optionCtrl; qt->out << GESetWidgetSize << QSize(term->xmax, term->ymax)/qt_oversampling; // Initialize the scene qt->out << GESetSceneSize << QSize(term->xmax, term->ymax)/qt_oversampling; qt->out << GEClear; // Initialize the font qt->out << GESetFont << qt->currentFontName << qt->currentFontSize; }
void qt_set_clipboard(const char s[]) { qt_out << GECopyClipboard << s; qt_flushOutBuffer(); }
void qt_set_ruler(int x, int y) { qt_out << GERuler << qt_termCoord(x, y); qt_flushOutBuffer(); }