6 #include <QCoreApplication>
16 #include <QPaintEvent>
18 #include <QProgressBar>
21 #include <qwindowsystem_qws.h>
48 LOG(VB_GENERAL, LOG_ALERT,
49 "Trying to create a dialog without a parent.");
72 setAutoFillBackground(
true);
120 LOG(VB_GENERAL, LOG_ALERT,
121 QString(
"MythDialog::setResult(%1) "
122 "called with invalid DialogCode").arg(r));
139 LOG(VB_GENERAL, LOG_ALERT,
140 QString(
"MythDialog::AcceptItem(%1) "
141 "called with negative index").arg(i));
168 LOG(VB_GENERAL, LOG_ALERT,
169 "MythDialog::exec: Recursive call detected.");
179 QEventLoop eventLoop;
204 bool handled =
false;
209 for (
int i = 0; i < actions.size() && !handled; i++)
211 QString
action = actions[i];
214 if (action ==
"ESCAPE")
216 else if (action ==
"UP" || action ==
"LEFT")
219 (focusWidget()->focusPolicy() == Qt::StrongFocus ||
220 focusWidget()->focusPolicy() == Qt::WheelFocus))
224 focusNextPrevChild(
false);
226 else if (action ==
"DOWN" || action ==
"RIGHT")
229 (focusWidget()->focusPolicy() == Qt::StrongFocus ||
230 focusWidget()->focusPolicy() == Qt::WheelFocus))
234 focusNextPrevChild(
true);
236 else if (action ==
"MENU")
266 setFrameShape(QFrame::Panel);
267 setFrameShadow(QFrame::Raised);
268 setPalette(parent->palette());
270 setFont(parent->font());
275 vbox =
new QVBoxLayout(
this);
276 vbox->setMargin((
int)(10 * hmult));
278 setAutoFillBackground(
true);
279 setWindowFlags(Qt::FramelessWindowHint);
283 QColor popupForeground, QColor popupBackground,
284 QColor popupHighlight,
const char *
name)
293 setFrameShape(QFrame::Panel);
294 setFrameShadow(QFrame::Raised);
295 setFrameStyle(QFrame::Box | QFrame::Plain);
296 setPalette(parent->palette());
297 setFont(parent->font());
302 vbox =
new QVBoxLayout(
this);
303 vbox->setMargin((
int)(10 * hmult));
308 palette.setColor(backgroundRole(), popupBackground);
315 palette.setColor(foregroundRole(), popupHighlight);
319 setAutoFillBackground(
true);
320 setWindowFlags(Qt::FramelessWindowHint);
328 QList<QWidget *> objList = qFindChildren<QWidget *>(
this);
330 QWidget *pCurr = focusWidget();
331 QWidget *pNew = NULL;
335 for (nIdx = 0; nIdx < objList.size(); ++nIdx )
337 if (objList[ nIdx ] == pCurr)
355 if (nIdx == objList.size())
363 nIdx = objList.size() -1;
366 pNew = objList[ nIdx ];
368 if (pNew && !pNew->focusProxy() && pNew->isVisibleTo(
this ) &&
369 pNew->isEnabled() && (pNew->focusPolicy() != Qt::NoFocus))
375 while (nIdx != nCurrIdx);
380 QFocusData *focusList = focusData();
381 QObjectList *objList = queryList(NULL,NULL,
false,
true);
383 QWidget *startingPoint = focusList->home();
384 QWidget *candidate = NULL;
386 QWidget *
w = (
next) ? focusList->prev() : focusList->next();
388 int countdown = focusList->count();
392 if (w && w != startingPoint && !w->focusProxy() &&
393 w->isVisibleTo(
this) && w->isEnabled() &&
394 (objList->find((QObject *)w) != -1))
399 w = (
next) ? focusList->prev() : focusList->next();
401 while (w && !(candidate && w == startingPoint) && (countdown-- > 0));
406 candidate->setFocus();
413 if (setAppearance ==
true)
415 widget->setPalette(palette());
416 widget->setFont(font());
419 if (widget->metaObject()->className() == QString(
"QLabel"))
423 widget->setPalette(palette);
426 vbox->addWidget(widget);
431 QLabel *label =
new QLabel(caption,
this);
439 label->setMaximumWidth((
int)
m_parent->width() / 2);
442 QChar::Direction text_dir = QChar::DirL;
444 if (caption.length())
445 text_dir = caption[0].direction();
446 Qt::Alignment align = (QChar::DirAL == text_dir) ?
447 Qt::AlignRight : Qt::AlignLeft;
448 label->setAlignment(align);
449 label->setWordWrap(
true);
452 label->setWordWrap(
true);
467 m_parent->connect(button, SIGNAL(pressed()), target, slot);
474 vbox->addLayout(layout, stretch);
483 QObject *target,
const char *slot)
485 QList< QObject* > objlist = children();
487 for (QList< QObject* >::Iterator it = objlist.begin();
493 if (objs->isWidgetType())
495 QWidget *widget = (QWidget *)objs;
496 widget->adjustSize();
502 int x = 0,
y = 0, maxw = 0, poph = 0;
504 for (QList< QObject* >::Iterator it = objlist.begin();
510 if (objs->isWidgetType())
512 QString objname = objs->objectName();
513 if (objname !=
"nopopsize")
516 if (objs->metaObject()->className() ==
517 QString(
"MythListBox"))
522 QWidget *widget = (QWidget *)objs;
523 poph += widget->height();
524 if (widget->width() > maxw)
525 maxw = widget->width();
531 setMinimumHeight(poph);
536 int height = (
int)(600 * hmult);
540 width = parentWidget()->width();
541 height = parentWidget()->height();
545 x = (
int)(width / 2) - (
int)(maxw / 2);
550 y = (
int)(height / 2) - (
int)(poph / 2);
554 if (poph +
y > height)
555 y = height - poph - (
int)(8 * hmult);
557 setFixedSize(maxw, poph);
558 setGeometry(x,
y, maxw, poph);
561 connect(
this, SIGNAL(
popupDone(
int)), target, slot);
568 bool handled =
false;
572 for (
int i = 0; i < actions.size() && !handled; i++)
574 QString
action = actions[i];
576 if (action ==
"ESCAPE")
616 QObject *target,
const char *slot)
628 QList< QObject* > objlist = children();
631 bool foundbutton =
false;
633 for (QList< QObject* >::Iterator it = objlist.begin();
639 if (objs->isWidgetType())
641 QWidget *widget = (QWidget *)objs;
642 if (widget->metaObject()->className() ==
643 QString(
"MythPushButton"))
645 if (widget->hasFocus())
662 for (QList< QObject* >::Iterator it = objlist.begin();
668 if (objs->isWidgetType())
670 QWidget *widget = (QWidget *)objs;
671 if (widget->metaObject()->className() ==
672 QString(
"MythPushButton"))
675 if (button && button->isDown())
690 LOG(VB_GENERAL, LOG_ALERT,
"We should never get here!");
696 const QString &title,
697 const QString &message,
700 if (button_msg.isEmpty())
701 button_msg = QObject::tr(
"OK");
706 QAbstractButton *okButton = popup->
addButton(button_msg, popup, SLOT(
accept()));
707 okButton->setFocus();
717 QString message, QString& text)
732 textEdit->setFocus();
736 text = textEdit->
text();
746 const QString &title,
const QString &message,
747 const QString &button1msg,
const QString &button2msg,
750 QStringList buttonmsgs;
751 buttonmsgs += (button1msg.isEmpty()) ?
752 QString(
"Button 1") : button1msg;
753 buttonmsgs += (button2msg.isEmpty()) ?
754 QString(
"Button 2") : button2msg;
756 parent, title, message, buttonmsgs, default_button);
761 const QString &title,
762 const QString &message,
763 const QStringList &buttonmsgs,
772 for (
int i = 0; i < buttonmsgs.size(); i++ )
774 QAbstractButton *but = popup->
addButton(buttonmsgs[i]);
788 const QString &message,
int totalSteps,
789 bool cancelButton,
const QObject *target,
const char *slot)
792 setObjectName(
"MythProgressDialog");
802 int yoff = screenheight / 3;
803 int xoff = screenwidth / 10;
804 setGeometry(xoff, yoff, screenwidth - xoff * 2, yoff);
805 setFixedSize(QSize(screenwidth - xoff * 2, yoff));
810 QVBoxLayout *vlayout =
new QVBoxLayout();
816 QHBoxLayout *hlayout =
new QHBoxLayout();
819 if (cancelButton && slot && target)
822 QObject::tr(
"Cancel"), NULL);
824 hlayout->addWidget(button);
825 connect(button, SIGNAL(
pressed()), target, slot);
832 QList<LCDTextItem> textItems;
836 lcddev->switchToGeneric(textItems);
839 hlayout->setSpacing(5);
841 vlayout->setMargin((
int)(15 * wmult));
842 vlayout->setStretchFactor(
msglabel, 5);
844 QWidget *hbox =
new QWidget();
845 hbox->setLayout(hlayout);
846 vlayout->addWidget(hbox);
848 QFrame *vbox =
new QFrame(
this);
849 vbox->setObjectName(objectName() +
"_vbox");
850 vbox->setLineWidth(3);
851 vbox->setMidLineWidth(3);
852 vbox->setFrameShape(QFrame::Panel);
853 vbox->setFrameShadow(QFrame::Raised);
854 vbox->setLayout(vlayout);
856 QVBoxLayout *lay =
new QVBoxLayout();
857 lay->addWidget(vbox);
862 qApp->processEvents();
890 if (curprogress %
steps == 0)
892 qApp->processEvents();
896 lcddev->setGenericProgress(fProgress);
908 bool handled =
false;
912 for (
int i = 0; i < actions.size() && !handled; i++)
914 QString
action = actions[i];
915 if (action ==
"ESCAPE")
927 steps = totalSteps / 1000;
933 const QString &window_name,
934 const QString &theme_filename,
945 QString msg = tr(
"Could not locate '%1' in theme '%2'."
946 "\n\nReturning to the previous menu.")
947 .arg(window_name).arg(theme_filename);
949 tr(
"Missing UI Element"), msg);
957 MythDialog(parent, name, setsize), widget_with_current_focus(NULL),
958 theme(NULL), context(-1)
964 QString theme_filename)
995 vector<UIType *> *all_ui_type_objects = looper->
getAllTypes();
996 vector<UIType *>::iterator i = all_ui_type_objects->begin();
997 for (; i != all_ui_type_objects->end(); ++i)
1000 connect(type, SIGNAL(requestUpdate()),
this,
1002 connect(type, SIGNAL(requestUpdate(
const QRect &)),
this,
1004 connect(type, SIGNAL(requestRegionUpdate(
const QRect &)),
this,
1027 QList<LayerSet*>::iterator another_it =
my_containers.begin();
1032 vector<UIType *> *all_ui_type_objects = looper->
getAllTypes();
1033 vector<UIType *>::iterator i = all_ui_type_objects->begin();
1034 for (; i != all_ui_type_objects->end(); ++i)
1074 for (QDomNode child = element.firstChild(); !child.isNull();
1075 child = child.nextSibling())
1077 QDomElement e = child.toElement();
1080 if (e.tagName() ==
"font")
1084 else if (e.tagName() ==
"container")
1090 LOG(VB_GENERAL, LOG_ALERT,
1091 QString(
"MythThemedDialog::loadWindow(): Do not "
1092 "understand DOM Element: '%1'. Ignoring.")
1111 if (name.length() < 1)
1113 LOG(VB_GENERAL, LOG_ALERT,
1114 "Failed to parse a container. Ignoring.");
1144 QPixmap bground(
size());
1145 bground.fill(
this, 0, 0);
1147 QPainter
tmp(&bground);
1174 setPalette(palette);
1179 QRect
r = this->geometry();
1184 " a screen update of zero size. A widget probably has not done"
1185 " calculateScreeArea(). Will redraw the whole screen (inefficient!).");
1189 QRect rect_to_update =
r;
1190 if (r.width() == 0 || r.height() == 0)
1193 rect_to_update = this->geometry();
1203 QRect rect_to_update =
r;
1204 if (r.width() == 0 || r.height() == 0)
1207 rect_to_update = this->geometry();
1233 whole_dialog_painter.drawPixmap(inv_rect.topLeft(),
my_background,
1248 const QRect intersect = inv_rect.intersect(container_area);
1250 if (container_area.isValid() &&
1251 (looper_context ==
context || looper_context == -1) &&
1252 intersect.isValid() &&
1253 looper->
GetName().toLower() !=
"background")
1259 LOG(VB_GENERAL, LOG_DEBUG,
1260 QString(
"A container called \"%1\" said its "
1261 "area is %2,%3 to %4,%5")
1263 .arg(container_area.left())
1264 .arg(container_area.top())
1265 .arg(container_area.left() + container_area.width())
1266 .arg(container_area.top() + container_area.height()));
1272 whole_dialog_painter.save();
1274 whole_dialog_painter.setClipRect(intersect);
1275 whole_dialog_painter.translate(container_area.left(),
1276 container_area.top());
1278 for (
int i = 0; i <= looper->
getLayers(); ++i)
1283 whole_dialog_painter.restore();
1295 p.drawPixmap(e->rect().topLeft(),
my_foreground, e->rect());
1326 bool reached_current =
false;
1342 reached_current=
true;
1354 bool reached_current =
false;
1371 reached_current=
true;
1375 if (reached_current)
1404 LOG(VB_GENERAL, LOG_ALERT,
"MythThemedDialog::activateCurrent() - "
1405 "there is no current widget!");
1411 template <
typename T>
1417 T *ret =
dynamic_cast<T *
>(sf);
1439 UIType *hunter = (*an_it)->GetType(name);
1459 vector<UIType*>::iterator it =
1474 return GetUIType<UIKeyboardType>(
this,
name);
1482 if ((*an_it)->GetName() ==
name)