[mythtv] [PATCH] Exprimental mouse support
Mikael Magnusson
mikma at hem.passagen.se
Thu Oct 30 12:56:49 EST 2003
On Thu, Oct 30, 2003 at 04:57:26PM +0800, barryliu wrote:
> Hi,all,
> MythTV is a great project, I am now enjoying it. Thanks all
> developpers!!!
> Now I want to use my mouse in this program,and try to change some
> source code, but fail. Somebody knows how to do that? pls tell me,
> thanks
> a lot!
>
> Best regards,
> barry
>
>
Hello,
I have coded some mouse support. It's only experimental and far from
complete. I don't know if I will continue with it, but if anybody is
interested I have included the patch.
Regards,
Mikael
-------------- next part --------------
? mouse.diff
Index: libs/libmyth/mythdialogs.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythdialogs.cpp,v
retrieving revision 1.26
diff -u -r1.26 mythdialogs.cpp
--- libs/libmyth/mythdialogs.cpp 28 Oct 2003 21:48:29 -0000 1.26
+++ libs/libmyth/mythdialogs.cpp 30 Oct 2003 17:21:49 -0000
@@ -41,6 +41,13 @@
MythMainWindow::MythMainWindow(QWidget *parent, const char *name, bool modal)
: QDialog(parent, name, modal)
{
+ cursor_timer = new QTimer(this);
+ connect(cursor_timer, SIGNAL(timeout()), this, SLOT(cursorTimeOut()));
+ cursor_timer->start(2 * 1000, true);
+
+ qApp->installEventFilter( this );
+ qApp->setGlobalMouseTracking(true);
+
Init();
ignore_lirc_keys = false;
#ifdef USE_LIRC
@@ -53,6 +60,11 @@
#endif
}
+MythMainWindow::~MythMainWindow()
+{
+ qApp->setGlobalMouseTracking(false);
+}
+
void MythMainWindow::Init(void)
{
gContext->GetScreenSettings(xbase, screenwidth, wmult,
@@ -61,7 +73,6 @@
setFixedSize(QSize(screenwidth, screenheight));
setFont(gContext->GetMediumFont());
- setCursor(QCursor(Qt::BlankCursor));
gContext->ThemeWidget(this);
@@ -178,7 +189,10 @@
if (!key_target)
{
- QWidget *focus_widget = qApp->focusWidget();
+ MythMainWindow *myParent = gContext->GetMainWindow();
+ QWidget *current = myParent ? myParent->currentWidget() : NULL;
+ QWidget *focus_widget = current ? current->focusWidget() :
+ qApp->focusWidget();
if (focus_widget && focus_widget->isEnabled())
{
key_target = focus_widget;
@@ -196,9 +210,47 @@
return key_target;
}
+void MythMainWindow::cursorTimeOut()
+{
+ qApp->setOverrideCursor(QCursor(Qt::BlankCursor));
+}
+
+bool MythMainWindow::eventFilter( QObject *o, QEvent *e )
+{
+ //int type = e->type();
+ //qDebug("Object %s, event %d", o->name(), e->type());
+
+ if (e->type() == QEvent::FocusOut)
+ {
+ QFocusEvent *f = (QFocusEvent *)e;
+
+ if (f->reason() == QFocusEvent::ActiveWindow)
+ {
+ // Eat event.
+ //return true;
+ }
+
+ return false;
+ }
+ else if (e->type() == QEvent::MouseMove)
+ {
+ //QMouseEvent *m = (QMouseEvent *)e;
+
+ if (!cursor_timer->isActive())
+ {
+ qApp->restoreOverrideCursor();
+ }
+
+ cursor_timer->start(2 * 1000, true);
+ }
+
+ return QDialog::eventFilter(o, e);
+}
+
MythDialog::MythDialog(MythMainWindow *parent, const char *name, bool setsize)
: QFrame(parent, name)
{
+// setWFlags(getWFlags() | Qt::WX11BypassWM);
rescode = 0;
if (!parent)
@@ -217,7 +269,6 @@
defaultSmallFont = gContext->GetSmallFont();
setFont(defaultMediumFont);
- setCursor(QCursor(Qt::BlankCursor));
if (setsize)
{
@@ -346,7 +397,6 @@
setFrameShadow(QFrame::Raised);
setPalette(parent->palette());
setFont(parent->font());
- setCursor(QCursor(Qt::BlankCursor));
hpadding = 110;
wpadding = 80;
@@ -600,7 +650,6 @@
gContext->GetScreenSettings(screenwidth, wmult, screenheight, hmult);
setFont(gContext->GetMediumFont());
- setCursor(QCursor(Qt::BlankCursor));
gContext->ThemeWidget(this);
@@ -1362,6 +1411,103 @@
return NULL;
}
+void MythThemedDialog::mouseReleaseEvent(QMouseEvent *e)
+{
+ if (e->button() == QMouseEvent::RightButton)
+ {
+ e->accept();
+ reject();
+ return;
+ }
+ else if (e->button() == QMouseEvent::LeftButton)
+ {
+ int x = e->x();
+ int y = e->y();
+ printf("MythThemedDialog::mouseReleaseEvent %d %d\n", x, y);
+
+ UIType *type = widget_with_current_focus;
+
+ if (type)
+ {
+
+ QRect rc = type->getScreenArea();
+
+ if (rc.contains(x, y))
+ {
+ printf("target %p %s %d %d \n",
+ type, type->getName().local8Bit().data(),
+ rc.x(), rc.y());
+
+ type->activate();
+ e->accept();
+ return;
+ }
+ }
+ }
+
+ MythDialog::mouseReleaseEvent(e);
+}
+
+void MythThemedDialog::mousePressEvent(QMouseEvent *e)
+{
+ if (e->button() != QMouseEvent::LeftButton)
+ {
+ MythDialog::mouseReleaseEvent(e);
+ return;
+ }
+
+ int x = e->x();
+ int y = e->y();
+ printf("MythThemedDialog::mouseReleaseEvent %d %d\n", x, y);
+
+ QPtrListIterator<LayerSet> an_it(my_containers);
+ LayerSet *looper;
+
+ while ((looper = an_it.current()) != 0)
+ {
+ QRect container_area = looper->GetAreaRect();
+
+ if (container_area.isValid() &&
+ container_area.contains(x, y) &&
+ looper->GetName().lower() != "background")
+ {
+ // Loop over UITypes within each container
+ vector<UIType *> *all_ui_type_objects = looper->getAllTypes();
+ vector<UIType *>::iterator i = all_ui_type_objects->begin();
+ for (; i != all_ui_type_objects->end(); i++)
+ {
+ UIType *type = (*i);
+ QRect rc = type->getScreenArea();
+
+ if (rc.contains(x, y))
+ {
+ printf("target %p %s %d %d \n",
+ type, type->getName().local8Bit().data(),
+ rc.x(), rc.y());
+
+ if (type->canTakeFocus())
+ {
+ if (widget_with_current_focus)
+ {
+ widget_with_current_focus->looseFocus();
+ }
+
+ widget_with_current_focus = type;
+ widget_with_current_focus->takeFocus();
+ }
+
+ e->accept();
+ return;
+ }
+ }
+ }
+ ++an_it;
+ }
+
+ MythDialog::mousePressEvent(e);
+}
+
+
/*
---------------------------------------------------------------------
*/
Index: libs/libmyth/mythdialogs.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythdialogs.h,v
retrieving revision 1.20
diff -u -r1.20 mythdialogs.h
--- libs/libmyth/mythdialogs.h 14 Oct 2003 03:54:46 -0000 1.20
+++ libs/libmyth/mythdialogs.h 30 Oct 2003 17:21:49 -0000
@@ -47,9 +47,11 @@
class MythMainWindow : public QDialog
{
+Q_OBJECT
public:
MythMainWindow(QWidget *parent = 0, const char *name = 0,
bool modal = FALSE);
+ virtual ~MythMainWindow();
void Init(void);
void Show(void);
@@ -58,6 +60,7 @@
void detach(QWidget *child);
QWidget *currentWidget(void);
+ bool eventFilter(QObject *o, QEvent *e);
protected:
void keyPressEvent(QKeyEvent *e);
@@ -72,6 +75,12 @@
vector<QWidget *> widgetList;
bool ignore_lirc_keys;
+
+ protected slots:
+ virtual void cursorTimeOut();
+
+ private:
+ QTimer *cursor_timer;
};
class MythDialog : public QFrame
@@ -218,6 +227,8 @@
void paintEvent(QPaintEvent* e);
UIType *widget_with_current_focus;
+ virtual void mousePressEvent(QMouseEvent *e);
+ virtual void mouseReleaseEvent(QMouseEvent *e);
//
// These need to be just "protected"
Index: libs/libmyth/themedmenu.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/themedmenu.cpp,v
retrieving revision 1.60
diff -u -r1.60 themedmenu.cpp
--- libs/libmyth/themedmenu.cpp 28 Oct 2003 21:48:29 -0000 1.60
+++ libs/libmyth/themedmenu.cpp 30 Oct 2003 17:21:50 -0000
@@ -1626,7 +1626,6 @@
setFixedSize(QSize(screenwidth, screenheight));
setFont(gContext->GetMediumFont());
- setCursor(QCursor(Qt::BlankCursor));
gContext->ThemeWidget(this);
@@ -1642,6 +1641,51 @@
parseMenu(file, row, col);
}
+void ThemedMenu::upMenu(bool forceExit)
+{
+ QString action = "UPMENU";
+ if (menulevel > 1)
+ handleAction(action);
+ else if (killable || forceExit)
+ done(0);
+}
+
+void ThemedMenu::updateButton(ThemedButton *lastbutton, int oldrow)
+{
+ if (!buttonRows[currentrow].visible)
+ {
+ makeRowVisible(currentrow, oldrow);
+ lastbutton = NULL;
+ }
+
+ activebutton = buttonRows[currentrow].buttons[currentcolumn];
+ if (lcddev)
+ {
+ // Build a list of the menu items
+ QPtrList<LCDMenuItem> menuItems;
+ menuItems.setAutoDelete(true);
+ bool selected;
+ for (int r = 0; r < (int)buttonRows.size(); r++)
+ {
+ if (r == currentrow)
+ selected = true;
+ else
+ selected = false;
+
+ if (currentcolumn < buttonRows[r].numitems)
+ menuItems.append(new LCDMenuItem(selected, NOTCHECKABLE,
+ buttonRows[r].buttons[currentcolumn]->text));
+ }
+
+ if (!menuItems.isEmpty())
+ lcddev->switchToMenu(&menuItems, titleText);
+ }
+ update(watermarkRect);
+ if (lastbutton)
+ update(lastbutton->posRect);
+ update(activebutton->posRect);
+}
+
void ThemedMenu::keyPressEvent(QKeyEvent *e)
{
if (ignorekeys)
@@ -1705,11 +1749,7 @@
}
case Key_Escape:
{
- QString action = "UPMENU";
- if (menulevel > 1)
- handleAction(action);
- else if (killable || e->state() == exitModifier)
- done(0);
+ upMenu(e->state() == exitModifier);
handled = true;
lastbutton = NULL;
break;
@@ -1719,44 +1759,88 @@
if (handled)
{
- if (!buttonRows[currentrow].visible)
+ updateButton(lastbutton, oldrow);
+ }
+ else
+ MythDialog::keyPressEvent(e);
+
+ ignorekeys = false;
+}
+
+void ThemedMenu::mousePressEvent(QMouseEvent *e)
+{
+ if (e->state() == 0)
+ {
+ int x = e->x();
+ int y = e->y();
+
+ ThemedButton *tbutton = buttonAt(x, y);
+
+ if (tbutton && tbutton != activebutton)
{
- makeRowVisible(currentrow, oldrow);
- lastbutton = NULL;
+ ThemedButton *lastbutton = activebutton;
+ activebutton = tbutton;
+ int oldrow = currentrow;
+
+ currentrow = tbutton->row - 1;
+ currentcolumn = tbutton->col - 1;
+
+ updateButton(lastbutton, oldrow);
+ e->accept();
+ return;
}
+ }
+
+ MythDialog::mousePressEvent(e);
+}
+
+
+void ThemedMenu::mouseReleaseEvent(QMouseEvent *e)
+{
+ if (e->button() == QMouseEvent::LeftButton)
+ {
+ int x = e->x();
+ int y = e->y();
+
+ ThemedButton *tbutton = buttonAt(x, y);
- activebutton = buttonRows[currentrow].buttons[currentcolumn];
- if (lcddev)
+ if (tbutton && tbutton == activebutton)
{
- // Build a list of the menu items
- QPtrList<LCDMenuItem> menuItems;
- menuItems.setAutoDelete(true);
- bool selected;
- for (int r = 0; r < (int)buttonRows.size(); r++)
+ handleAction(activebutton->action);
+ e->accept();
+ return;
+ }
+ else
+ {
+ bool needup = false;
+ bool needdown = false;
+
+ if (!buttonRows.front().visible)
+ needup = true;
+
+ if (!buttonRows.back().visible)
+ needdown = true;
+
+ if (needup && uparrowRect.contains(x, y))
{
- if (r == currentrow)
- selected = true;
- else
- selected = false;
-
- if (currentcolumn < buttonRows[r].numitems)
- menuItems.append(new LCDMenuItem(selected, NOTCHECKABLE,
- buttonRows[r].buttons[currentcolumn]->text));
+ printf("up\n");
+ }
+ else if (needdown && downarrowRect.contains(x, y))
+ {
+ printf("down\n");
}
-
- if (!menuItems.isEmpty())
- lcddev->switchToMenu(&menuItems, titleText);
}
- update(watermarkRect);
- if (lastbutton)
- update(lastbutton->posRect);
- update(activebutton->posRect);
}
- else
- MythDialog::keyPressEvent(e);
+ else if (e->button() == QMouseEvent::RightButton)
+ {
+ upMenu((e->state() & ~QMouseEvent::RightButton) == exitModifier);
+ e->accept();
+ return;
+ }
+
+ MythDialog::mouseReleaseEvent(e);
+}
- ignorekeys = false;
-}
QString ThemedMenu::findMenuFile(QString menuname)
{
@@ -1889,6 +1973,27 @@
return false;
}
+
+ThemedButton *ThemedMenu::buttonAt(int x, int y)
+{
+ vector<ThemedButton>::iterator iter;
+
+ for (iter = buttonList.begin(); iter != buttonList.end(); iter++)
+ {
+ ThemedButton *tbutton = &(*iter);
+
+ if (!tbutton->visible)
+ continue;
+
+ if (tbutton->posRect.contains(x, y))
+ {
+ return tbutton;
+ }
+ }
+
+ return NULL;
+}
+
bool ThemedMenu::checkPinCode(QString timestamp_setting,
QString password_setting, QString text)
{
Index: libs/libmyth/themedmenu.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/themedmenu.h,v
retrieving revision 1.30
diff -u -r1.30 themedmenu.h
--- libs/libmyth/themedmenu.h 14 Oct 2003 18:00:57 -0000 1.30
+++ libs/libmyth/themedmenu.h 30 Oct 2003 17:21:50 -0000
@@ -99,6 +99,9 @@
protected:
void paintEvent(QPaintEvent *e);
void keyPressEvent(QKeyEvent *e);
+ void mousePressEvent(QMouseEvent *e);
+ void mouseReleaseEvent(QMouseEvent *e);
+ ThemedButton *buttonAt(int x, int y);
private:
void parseMenu(QString menuname, int row = -1, int col = -1);
@@ -149,6 +152,8 @@
void drawScrollArrows(QPainter *p);
bool checkPinCode(QString timestamp_setting, QString password_setting,
QString text);
+ void upMenu(bool forceExit);
+ void updateButton(ThemedButton *lastbutton, int oldrow);
QString prefix;
More information about the mythtv-dev
mailing list