Skip to content

Commit

Permalink
Shell|Fixed: Refresh timing, rule usage
Browse files Browse the repository at this point in the history
If one starts another QEventLoop from a QTimer timeout(), the timer
is paused and would cause refresh to stop.

Now each refresh is scheduled as a single-shot signal.
  • Loading branch information
skyjake committed Jan 31, 2013
1 parent 24c3257 commit 5e87a3a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
23 changes: 11 additions & 12 deletions doomsday/tools/shell/shell-text/src/cursesapp.cpp
Expand Up @@ -82,7 +82,6 @@ struct CursesApp::Instance
// Curses state:
WINDOW *rootWin;
de::Vector2i rootSize;
QTimer *refreshTimer;
int unicodeContinuation;

TextRootWidget *rootWidget;
Expand Down Expand Up @@ -125,9 +124,7 @@ struct CursesApp::Instance
// Listen for window resizing.
signal(SIGWINCH, windowResized);

refreshTimer = new QTimer(&self);
QObject::connect(refreshTimer, SIGNAL(timeout()), &self, SLOT(refresh()));
refreshTimer->start(1000 / 30);
requestRefresh();
}

void initCursesState()
Expand All @@ -149,16 +146,18 @@ struct CursesApp::Instance

void shutdownCurses()
{
delete refreshTimer;
refreshTimer = 0;

delwin(rootWin);
rootWin = 0;

endwin();
refresh();
}

void requestRefresh()
{
QTimer::singleShot(1000 / 30, &self, SLOT(refresh()));
}

void handleResize()
{
// Terminal has been resized.
Expand All @@ -180,6 +179,9 @@ struct CursesApp::Instance
{
if(!rootWin) return;

// Schedule the next refresh.
requestRefresh();

// Update time.
clock.setTime(de::Time());

Expand Down Expand Up @@ -335,6 +337,8 @@ struct CursesApp::Instance
}
}

rootWidget->update();

// Automatically redraw the UI if the values of layout rules have changed.
if(de::Rule::invalidRulesExist() || rootWidget->drawWasRequested())
{
Expand All @@ -348,11 +352,6 @@ struct CursesApp::Instance
wrefresh(rootWin);
}
}

void update()
{
rootWidget->draw();
}
};

CursesApp::CursesApp(int &argc, char **argv)
Expand Down
19 changes: 10 additions & 9 deletions doomsday/tools/shell/shell-text/src/shellapp.cpp
Expand Up @@ -47,23 +47,24 @@ struct ShellApp::Instance
// Status bar in the bottom of the view.
status = new StatusWidget;
status->rule()
.setInput(RuleRectangle::Height, refless(new ConstantRule(1)))
.setInput(RuleRectangle::Height, *refless(new ConstantRule(1)))
.setInput(RuleRectangle::Bottom, root.viewBottom())
.setInput(RuleRectangle::Width, root.viewWidth())
.setInput(RuleRectangle::Left, root.viewLeft());

// Menu button at the left edge.
menuLabel = new LabelWidget;
menuLabel->setAlignment(AlignTop);
menuLabel->setLabel(" F9:Menu ");
menuLabel->setLabel(tr(" F9:Menu "));
menuLabel->setAttribs(TextCanvas::Char::Bold);
menuLabel->rule()
.setInput(RuleRectangle::Left, root.viewLeft())
.setInput(RuleRectangle::Width, refless(new ConstantRule(menuLabel->label().size())))
.setInput(RuleRectangle::Width, *refless(new ConstantRule(menuLabel->label().size())))
.setInput(RuleRectangle::Bottom, status->rule().top());

menuLabel->addAction(new Action(KeyEvent(Qt::Key_F9), &self, SLOT(openMenu())));
menuLabel->addAction(new Action(KeyEvent(Qt::Key_Z, KeyEvent::Control), &self, SLOT(openMenu())));
menuLabel->addAction(new Action(KeyEvent(Qt::Key_X, KeyEvent::Control), &self, SLOT(openMenu())));
menuLabel->addAction(new Action(KeyEvent(Qt::Key_C, KeyEvent::Control), &self, SLOT(openMenu())));

// Expanding command line widget.
Expand All @@ -86,15 +87,15 @@ struct ShellApp::Instance
// Main menu.
menu = new MenuWidget;
menu->hide(); // closed initially
menu->appendItem(new Action("Connect to...",
KeyEvent(Qt::Key_O),
menu->appendItem(new Action(tr("Connect to..."),
KeyEvent("o"),
&self, SLOT(openConnection())), "O");
menu->appendItem(new Action("Disconnect"));
menu->appendItem(new Action(tr("Disconnect")));
menu->appendSeparator();
menu->appendItem(new Action("Start new server"));
menu->appendItem(new Action(tr("Start new server")));
menu->appendSeparator();
menu->appendItem(new Action("About"));
menu->appendItem(new Action("Quit Shell",
menu->appendItem(new Action(tr("About")));
menu->appendItem(new Action(tr("Quit Shell"),
KeyEvent(Qt::Key_X, KeyEvent::Control),
&self, SLOT(quit())), "Ctrl-X");
menu->rule()
Expand Down

0 comments on commit 5e87a3a

Please sign in to comment.