[rkward-cvs] SF.net SVN: rkward-code:[4725] trunk/rkward
tfry at users.sf.net
tfry at users.sf.net
Fri Apr 26 08:21:22 UTC 2013
Revision: 4725
http://sourceforge.net/p/rkward/code/4725
Author: tfry
Date: 2013-04-26 08:21:21 +0000 (Fri, 26 Apr 2013)
Log Message:
-----------
Better status feedback when the device is in interactive state (RK()-device, only)
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h
trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc
trunk/rkward/rkward/windows/rkwindowcatcher.cpp
trunk/rkward/rkward/windows/rkwindowcatcher.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2013-04-26 08:06:09 UTC (rev 4724)
+++ trunk/rkward/ChangeLog 2013-04-26 08:21:21 UTC (rev 4725)
@@ -5,7 +5,6 @@
- The script editor's "Run line" and "Run selection" actions have been merged
- New (experimental) RKWard native on-screen device (RK())
TODO: Finish it, then provide UI option to select on-screen device
- - Improve feedback when device is waiting for input
- New R function rk.without.plot.history() for turning off plot history, temporarily
- Add command line option --backend-debugger
Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp 2013-04-26 08:06:09 UTC (rev 4724)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp 2013-04-26 08:21:21 UTC (rev 4725)
@@ -78,10 +78,15 @@
view->resize (area.size ());
view->show ();
}
+ checkSize ();
+ painter.begin (&area);
+}
+
+void RKGraphicsDevice::checkSize() {
+ RK_TRACE (GRAPHICS_DEVICE);
if (view->size () != area.size ()) {
RKGlobals::rInterface ()->issueCommand (new RCommand ("rkward:::RK.resize (" + QString::number (devices.key (this) + 1) + ")", RCommand::PriorityCommand));
}
- painter.begin (&area);
}
RKGraphicsDevice* RKGraphicsDevice::newDevice (int devnum, double width, double height, const QString &title, bool antialias) {
@@ -232,18 +237,29 @@
emit (captionChanged (view->windowTitle ()));
}
-void RKGraphicsDevice::locator () {
+void RKGraphicsDevice::goInteractive (const QString& prompt) {
RK_TRACE (GRAPHICS_DEVICE);
- RK_ASSERT (interaction_opcode < 0);
- interaction_opcode = RKDLocator;
-
+ // The backend does not support trying to resize while it is waiting for a reply, and will produce error message in this case.
+ // To avoid confusion and loads of scary error messages, we disable resizing in the frontend while interactive.
+ // NOTE: It would certainly be possible, but rather cumbersome to support resizing during interaction in the backend.
+ // It does not seem to be important enough, however.
+ view->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
view->setCursor (Qt::CrossCursor);
- view->setToolTip (i18n ("<h2>Locating point(s)</h2><p>Use left mouse button to select point(s). Any other mouse button to stop.</p>"));
+ view->setToolTip (prompt);
view->show ();
view->raise ();
+ emit (goingInteractive (true, prompt));
}
+void RKGraphicsDevice::locator () {
+ RK_TRACE (GRAPHICS_DEVICE);
+
+ RK_ASSERT (interaction_opcode < 0);
+ interaction_opcode = RKDLocator;
+ goInteractive (i18n ("<h2>Locating point(s)</h2><p>Use left mouse button to select point(s). Any other mouse button to stop.</p>"));
+}
+
void RKGraphicsDevice::confirmNewPage () {
RK_TRACE (GRAPHICS_DEVICE);
@@ -251,12 +267,12 @@
RK_ASSERT (dialog == 0);
interaction_opcode = RKDNewPageConfirm;
- view->show ();
- view->raise ();
+ QString msg = i18n ("<p>Press Enter to see next plot, or click 'Cancel' to abort.</p>");
+ goInteractive (msg);
dialog = new KDialog (view);
dialog->setCaption (i18n ("Ok to show next plot?"));
dialog->setButtons (KDialog::Ok | KDialog::Cancel);
- dialog->setMainWidget (new QLabel (i18n ("<p>Press Enter to see next plot, or click 'Cancel' to abort.</p>"), dialog));
+ dialog->setMainWidget (new QLabel (msg, dialog));
// dialog->setWindowModality (Qt::WindowModal); // not good: Grays out the plot window
connect (dialog, SIGNAL (finished (int)), this, SLOT (newPageDialogDone (int)));
dialog->show ();
@@ -278,10 +294,7 @@
stored_events.clear ();
interaction_opcode = RKDStartGettingEvents;
- view->setCursor (Qt::CrossCursor);
- view->setToolTip (prompt);
- view->show ();
- view->raise ();
+ goInteractive (prompt);
}
RKGraphicsDevice::StoredEvent RKGraphicsDevice::fetchNextEvent () {
@@ -354,6 +367,17 @@
stored_events.append (sev);
return (true);
}
+ } else if (interaction_opcode == RKDNewPageConfirm) {
+ if (event->type () == QEvent::KeyPress) {
+ QKeyEvent *ke = static_cast<QKeyEvent*> (event);
+ if ((ke->key () == Qt::Key_Return) || (ke->key () == Qt::Key_Enter)) {
+ newPageDialogDone (KDialog::Accepted);
+ return true;
+ } else if (ke->key () == Qt::Key_Escape) {
+ newPageDialogDone (KDialog::Rejected);
+ return true;
+ }
+ }
}
if (event->type () == QEvent::Resize) triggerUpdate ();
@@ -384,7 +408,10 @@
if (view) { // might already be destroyed
view->setCursor (Qt::ArrowCursor);
view->setToolTip (QString ());
+ checkSize ();
+ view->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
}
+ emit (goingInteractive (false, QString ()));
interaction_opcode = -1;
}
Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h 2013-04-26 08:06:09 UTC (rev 4724)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h 2013-04-26 08:21:21 UTC (rev 4725)
@@ -76,6 +76,7 @@
public slots:
void stopInteraction ();
signals:
+ void goingInteractive (bool interactive, const QString &prompt);
void activeChanged (bool);
void locatorDone (bool ok, double x, double y);
void newPageConfirmDone (bool accepted);
@@ -85,7 +86,9 @@
void newPageDialogDone (int result);
void viewKilled ();
private:
+ void goInteractive (const QString &prompt);
bool eventFilter (QObject *watched, QEvent *event);
+ void checkSize ();
QTimer updatetimer;
QPixmap area;
Modified: trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc
===================================================================
--- trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc 2013-04-26 08:06:09 UTC (rev 4724)
+++ trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc 2013-04-26 08:21:21 UTC (rev 4725)
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui>
-<kpartgui name="rkward_x11window" version="54">
+<kpartgui name="rkward_x11window" version="620">
<MenuBar>
<Menu name="device"><text>&Device</text>
<Action name="device_activate"/>
@@ -46,5 +46,7 @@
<Action name="plot_next"/>
<Separator/>
<Action name="plot_remove"/>
+ <Separator/>
+ <Action name="stop_interaction"/>
</ToolBar>
</kpartgui>
\ No newline at end of file
Modified: trunk/rkward/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.cpp 2013-04-26 08:06:09 UTC (rev 4724)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.cpp 2013-04-26 08:21:21 UTC (rev 4725)
@@ -183,6 +183,9 @@
resize (xembed_container->size ());
rk_native_device->viewPort ()->setParent (xembed_container);
connect (rkward_device, SIGNAL (captionChanged(const QString&)), this, SLOT (setCaption(const QString &)));
+ connect (rkward_device, SIGNAL (goingInteractive(bool,const QString&)), this, SLOT (deviceInteractive(bool,const QString&)));
+ stop_interaction->setVisible (true);
+ stop_interaction->setEnabled (false);
setCaption (rkward_device->viewPort ()->windowTitle ());
QTimer::singleShot (0, this, SLOT (doEmbed()));
@@ -339,6 +342,28 @@
reEmbed ();
}
+void RKCaughtX11Window::deviceInteractive (bool interactive, const QString& prompt) {
+ RK_TRACE (MISC);
+
+ stop_interaction->setToolTip (prompt);
+ stop_interaction->setEnabled (interactive);
+
+ if (interactive) {
+ activate (true);
+ // it is necessary to do this also in the wrapper widget. Otherwise, for some reason, the view cannot be expanded, but can be shrunk.
+ setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
+ } else {
+ setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
+ }
+}
+
+void RKCaughtX11Window::stopInteraction () {
+ RK_TRACE (MISC);
+
+ RK_ASSERT (rk_native_device);
+ rk_native_device->stopInteraction ();
+}
+
void RKCaughtX11Window::fixedSizeToggled () {
RK_TRACE (MISC);
@@ -676,6 +701,11 @@
action->setText (i18n ("Duplicate"));
action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionWindowDuplicate));
+ action = window->stop_interaction = actionCollection ()->addAction ("stop_interaction", window, SLOT (stopInteraction ()));
+ action->setText (i18n ("Stop interaction"));
+ action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionInterrupt));
+ action->setVisible (false);
+
// initialize context for plugins
RKContextMap *context = RKComponentMap::getContext ("x11");
if (!context) return;
Modified: trunk/rkward/rkward/windows/rkwindowcatcher.h
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.h 2013-04-26 08:06:09 UTC (rev 4724)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.h 2013-04-26 08:21:21 UTC (rev 4725)
@@ -127,6 +127,8 @@
* NOTE: If no device exists (or isn't known to the system), this function does nothing */
static void setStatusMessage (int dev_num, const QString &message, RCommand *command=0);
public slots:
+ void deviceInteractive (bool interactive, const QString &prompt);
+
/** Fixed size action was (potentially) toggled. Update to the new state */
void fixedSizeToggled ();
/** Switch to fixed size mode, and set size1 (currently 500*500) */
@@ -143,6 +145,7 @@
void printDevice ();
void copyDeviceToRObject ();
void duplicateDevice ();
+ void stopInteraction ();
/** history navigation */
void firstPlot ();
@@ -197,6 +200,7 @@
KAction *plot_clear_history_action;
KAction *plot_properties_action;
KSelectAction *plot_list_action;
+ KAction *stop_interaction;
KPassivePopup* status_popup;
RCommand* status_change_command;
More information about the rkward-tracker
mailing list