31 #include <hbcolorscheme.h> |
31 #include <hbcolorscheme.h> |
32 #include <hbcssformatter_p.h> |
32 #include <hbcssformatter_p.h> |
33 #include <hbevent.h> |
33 #include <hbevent.h> |
34 #include <hbframedrawer.h> |
34 #include <hbframedrawer.h> |
35 #include <hbframeitem.h> |
35 #include <hbframeitem.h> |
|
36 #include <hbgraphicsscene_p.h> |
36 #include <hbiconitem.h> |
37 #include <hbiconitem.h> |
37 #include <hbinstance.h> |
38 #include <hbinstance.h> |
38 #include <hblayeredstyleloader_p.h> |
39 #include <hblayeredstyleloader_p.h> |
39 #include <hbmainwindow_p.h> |
40 #include <hbmainwindow_p.h> |
40 #include <hbmarqueeitem.h> |
41 #include <hbmarqueeitem.h> |
41 #include <hbnamespace_p.h> |
42 #include <hbnamespace_p.h> |
|
43 #include <hbpopupmanager_p.h> |
|
44 #include <hbpopupmanager_p_p.h> |
42 #include <hbscreen_p.h> |
45 #include <hbscreen_p.h> |
43 #include <hbtextitem.h> |
46 #include <hbtextitem.h> |
44 #include <hbwidgetloadersyntax_p.h> |
47 #include <hbwidgetloadersyntax_p.h> |
45 #include <hbxmlloaderabstractsyntax_p.h> |
48 #include <hbxmlloaderabstractsyntax_p.h> |
46 #include <hbwidgetbase_p.h> |
49 #include <hbwidgetbase_p.h> |
779 mLabel->setLayoutDirection(dir); |
783 mLabel->setLayoutDirection(dir); |
780 mTextBox->setLayoutDirection(dir); |
784 mTextBox->setLayoutDirection(dir); |
781 } |
785 } |
782 |
786 |
783 |
787 |
784 |
|
785 /******************************************************************************************/ |
788 /******************************************************************************************/ |
786 CssInspectorModelItem::CssInspectorModelItem(QGraphicsItem *item, int row, CssInspectorModelItem *parent) |
789 ModelItemWrapper::ModelItemWrapper(QGraphicsItem *item) |
|
790 : mGraphicsItem(item), mWindow(0), mPopupMgr(0) |
|
791 { |
|
792 } |
|
793 |
|
794 ModelItemWrapper::ModelItemWrapper(HbMainWindow *win) |
|
795 : mGraphicsItem(0), mWindow(win), mPopupMgr(0) |
|
796 { |
|
797 } |
|
798 |
|
799 ModelItemWrapper::ModelItemWrapper(HbPopupManager *mgr) |
|
800 : mGraphicsItem(0), mWindow(0), mPopupMgr(mgr) |
|
801 { |
|
802 } |
|
803 |
|
804 ModelItemWrapper::ModelItemWrapper() |
|
805 : mGraphicsItem(0), mWindow(0), mPopupMgr(0) |
|
806 { |
|
807 } |
|
808 |
|
809 QGraphicsItem* ModelItemWrapper::graphicsItem() const |
|
810 { |
|
811 return mGraphicsItem; |
|
812 } |
|
813 |
|
814 HbMainWindow* ModelItemWrapper::window() const |
|
815 { |
|
816 return mWindow; |
|
817 } |
|
818 |
|
819 HbPopupManager* ModelItemWrapper::popupManager() const |
|
820 { |
|
821 return mPopupMgr; |
|
822 } |
|
823 |
|
824 |
|
825 /******************************************************************************************/ |
|
826 CssInspectorModelItem::CssInspectorModelItem(ModelItemWrapper *item, int row, CssInspectorModelItem *parent) |
787 : mItem(item), mParent(parent), mRow(row) |
827 : mItem(item), mParent(parent), mRow(row) |
788 { |
828 { |
789 } |
829 } |
790 |
830 |
791 CssInspectorModelItem::~CssInspectorModelItem() |
831 CssInspectorModelItem::~CssInspectorModelItem() |
792 { |
832 { |
793 QHash<int, CssInspectorModelItem*>::iterator it; |
833 QHash<int, CssInspectorModelItem*>::iterator it; |
794 for (it = mChildren.begin(); it!= mChildren.end(); ++it) |
834 for (it = mChildren.begin(); it!= mChildren.end(); ++it) |
795 delete it.value(); |
835 delete it.value(); |
|
836 delete mItem; |
796 } |
837 } |
797 |
838 |
798 CssInspectorModelItem* CssInspectorModelItem::child(int i) |
839 CssInspectorModelItem* CssInspectorModelItem::child(int i) |
799 { |
840 { |
800 if (mChildren.contains(i)) |
841 if (mChildren.contains(i)) |
801 return mChildren[i]; |
842 return mChildren[i]; |
802 |
843 |
803 if (i>=0 && i < mItem->childItems().count()) { |
844 if (i < 0) |
804 QGraphicsItem *child = mItem->childItems().at(i); |
845 return 0; |
805 CssInspectorModelItem *childItem = new CssInspectorModelItem(child, i, this); |
846 |
|
847 ModelItemWrapper *wrapper = 0; |
|
848 if (mItem->graphicsItem() && i < mItem->graphicsItem()->childItems().count()) { |
|
849 QGraphicsItem *child = mItem->graphicsItem()->childItems().at(i); |
|
850 wrapper = new ModelItemWrapper(child); |
|
851 } else if (mItem->popupManager() && i < mItem->popupManager()->d->popupList.count()) { |
|
852 HbPopup *popup = mItem->popupManager()->d->popupList.at(i); |
|
853 wrapper = new ModelItemWrapper(popup); |
|
854 } else if (mItem->window()) { |
|
855 HbMainWindowPrivate *winPriv = HbMainWindowPrivate::d_ptr(mItem->window()); |
|
856 QGraphicsItem *screen = winPriv->element(HbMainWindowPrivate::ViewportItem); |
|
857 if (i < screen->childItems().count()) { |
|
858 wrapper = new ModelItemWrapper(screen->childItems().at(i)); |
|
859 } else if (i == screen->childItems().count()) { |
|
860 // Out of bounds due to zero index, return popup manager (this is a special case) |
|
861 HbGraphicsScenePrivate *scenePriv = HbGraphicsScenePrivate::d_ptr(winPriv->mScene); |
|
862 HbPopupManager *mgr = scenePriv->popupManager(); |
|
863 wrapper = new ModelItemWrapper(mgr); |
|
864 } |
|
865 } else { |
|
866 // Root node, return from all main windows |
|
867 if (i < hbInstance->allMainWindows().count()) { |
|
868 HbMainWindow *win = hbInstance->allMainWindows().at(i); |
|
869 wrapper = new ModelItemWrapper(win); |
|
870 } |
|
871 } |
|
872 |
|
873 if (wrapper) { |
|
874 CssInspectorModelItem *childItem = new CssInspectorModelItem(wrapper, i, this); |
806 mChildren[i] = childItem; |
875 mChildren[i] = childItem; |
807 return childItem; |
876 return childItem; |
808 } |
877 } |
|
878 |
809 return 0; |
879 return 0; |
810 } |
880 } |
811 |
881 |
812 CssInspectorModelItem* CssInspectorModelItem::parent() |
882 CssInspectorModelItem* CssInspectorModelItem::parent() |
813 { |
883 { |
814 return mParent; |
884 return mParent; |
815 } |
885 } |
816 |
886 |
817 QGraphicsItem* CssInspectorModelItem::data() |
887 ModelItemWrapper* CssInspectorModelItem::data() |
818 { |
888 { |
819 return mItem; |
889 return mItem; |
820 } |
890 } |
821 |
891 |
822 int CssInspectorModelItem::row() |
892 int CssInspectorModelItem::row() |
823 { |
893 { |
824 return mRow; |
894 return mRow; |
825 } |
895 } |
826 |
896 |
827 /******************************************************************************************/ |
897 /******************************************************************************************/ |
828 CssInspectorModel::CssInspectorModel(HbMainWindow *win, QObject *parent) |
898 CssInspectorModel::CssInspectorModel(QObject *parent) |
829 : QAbstractItemModel(parent), mWin(win), mRootItem(0) |
899 : QAbstractItemModel(parent), mRootItem(0) |
830 { |
900 { |
831 QGraphicsItem *screen = HbMainWindowPrivate::d_ptr(win)->mClippingItem; |
901 mRootItem = new CssInspectorModelItem(new ModelItemWrapper, 0); |
832 mRootItem = new CssInspectorModelItem(screen, 0); |
|
833 } |
902 } |
834 |
903 |
835 CssInspectorModel::~CssInspectorModel() |
904 CssInspectorModel::~CssInspectorModel() |
836 { |
905 { |
837 delete mRootItem; |
906 delete mRootItem; |
841 { |
910 { |
842 if (!index.isValid() || role != Qt::DisplayRole) |
911 if (!index.isValid() || role != Qt::DisplayRole) |
843 return QVariant(); |
912 return QVariant(); |
844 |
913 |
845 CssInspectorModelItem *item = static_cast<CssInspectorModelItem*>(index.internalPointer()); |
914 CssInspectorModelItem *item = static_cast<CssInspectorModelItem*>(index.internalPointer()); |
846 QGraphicsItem *graphicsItem = item->data(); |
915 QGraphicsItem *graphicsItem = item->data()->graphicsItem(); |
847 |
916 |
848 switch (index.column()) { |
917 if (graphicsItem) { |
849 case 0: return itemClass(graphicsItem); |
918 switch (index.column()) { |
850 case 1: return objName(graphicsItem); |
919 case 0: return itemClass(graphicsItem); |
851 case 2: return HbStyle::itemName(graphicsItem); |
920 case 1: return objName(graphicsItem); |
852 case 3: return itemValue(graphicsItem); |
921 case 2: return HbStyle::itemName(graphicsItem); |
853 case 4: return itemInParentLayout(graphicsItem); |
922 case 3: return itemValue(graphicsItem); |
|
923 case 4: return itemInParentLayout(graphicsItem); |
|
924 default: return QVariant(); |
|
925 } |
|
926 } else { |
|
927 if (index.column() == 0) { |
|
928 // Return correct item name |
|
929 if (item->data()->popupManager()) { |
|
930 return "HbPopupManager"; |
|
931 } else if (item->data()->window()) { |
|
932 return "HbScreen"; |
|
933 } |
|
934 } |
854 } |
935 } |
855 return QVariant(); |
936 return QVariant(); |
856 } |
937 } |
857 |
938 |
858 QVariant CssInspectorModel::headerData(int section, Qt::Orientation orientation, int role) const |
939 QVariant CssInspectorModel::headerData(int section, Qt::Orientation orientation, int role) const |
911 if (!parent.isValid()) |
992 if (!parent.isValid()) |
912 parentItem = mRootItem; |
993 parentItem = mRootItem; |
913 else |
994 else |
914 parentItem = static_cast<CssInspectorModelItem*>(parent.internalPointer()); |
995 parentItem = static_cast<CssInspectorModelItem*>(parent.internalPointer()); |
915 |
996 |
916 return parentItem->data()->childItems().count(); |
997 ModelItemWrapper *wrapper = parentItem->data(); |
|
998 if (wrapper->graphicsItem()) { |
|
999 return wrapper->graphicsItem()->childItems().count(); |
|
1000 } else if (wrapper->popupManager()) { |
|
1001 return wrapper->popupManager()->d->popupList.count(); |
|
1002 } else if (wrapper->window()) { |
|
1003 HbMainWindowPrivate *winPriv = HbMainWindowPrivate::d_ptr(wrapper->window()); |
|
1004 QGraphicsItem *screen = winPriv->element(HbMainWindowPrivate::ViewportItem); |
|
1005 return screen->childItems().count() + 1; // Special case to add PopupManager |
|
1006 } else { |
|
1007 return hbInstance->allMainWindows().count(); |
|
1008 } |
917 } |
1009 } |
918 |
1010 |
919 int CssInspectorModel::columnCount(const QModelIndex &parent) const |
1011 int CssInspectorModel::columnCount(const QModelIndex &parent) const |
920 { |
1012 { |
921 Q_UNUSED(parent) |
1013 Q_UNUSED(parent) |
998 mTreeView->header()->resizeSections(QHeaderView::ResizeToContents); |
1095 mTreeView->header()->resizeSections(QHeaderView::ResizeToContents); |
999 } |
1096 } |
1000 |
1097 |
1001 void HbCssInspectorWindow::addFilters() |
1098 void HbCssInspectorWindow::addFilters() |
1002 { |
1099 { |
1003 foreach (HbMainWindow *window, hbInstance->allMainWindows()) { |
1100 mTreeView->setModel(new CssInspectorModel); |
1004 mTreeView->setModel(new CssInspectorModel(window)); |
1101 |
1005 |
1102 foreach (const HbMainWindow *window, hbInstance->allMainWindows()) { |
1006 HoveredWidgetFilter *filter = new HoveredWidgetFilter(window->scene()); |
1103 HoveredWidgetFilter *filter = new HoveredWidgetFilter(window->scene()); |
1007 window->scene()->installEventFilter(filter); |
1104 window->scene()->installEventFilter(filter); |
1008 mInstalledFilters.append(filter); |
1105 mInstalledFilters.append(filter); |
1009 connect(filter, SIGNAL(newItemHovered(const QGraphicsItem*)), |
1106 connect(filter, SIGNAL(newItemHovered(const QGraphicsItem*)), |
1010 SLOT(updateFocusItem(const QGraphicsItem*))); |
1107 SLOT(updateFocusItem(const QGraphicsItem*))); |
1125 QVBoxLayout *treeLayout = new QVBoxLayout; |
1222 QVBoxLayout *treeLayout = new QVBoxLayout; |
1126 treeLayout->setContentsMargins(0,0,0,0); |
1223 treeLayout->setContentsMargins(0,0,0,0); |
1127 treeContainer->setLayout(treeLayout); |
1224 treeContainer->setLayout(treeLayout); |
1128 mTreeView = new QTreeView(this); |
1225 mTreeView = new QTreeView(this); |
1129 mTreeView->setItemDelegate(new ItemColorDelegate); |
1226 mTreeView->setItemDelegate(new ItemColorDelegate); |
|
1227 mTreeView->setAttribute(Qt::WA_InputMethodEnabled, false); |
1130 QLabel *treeLabel = new QLabel(tr("Item tree")); |
1228 QLabel *treeLabel = new QLabel(tr("Item tree")); |
1131 treeLayout->addWidget(treeLabel); |
1229 treeLayout->addWidget(treeLabel); |
1132 treeLayout->addWidget(mTreeView); |
1230 treeLayout->addWidget(mTreeView); |
1133 |
1231 |
1134 connect(mTreeView, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(updateColumnSizes(const QModelIndex&))); |
1232 connect(mTreeView, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(updateColumnSizes(const QModelIndex&))); |
1250 const QGraphicsItem *ancestor = item; |
1348 const QGraphicsItem *ancestor = item; |
1251 while (ancestor) { |
1349 while (ancestor) { |
1252 ancestorItems << ancestor; |
1350 ancestorItems << ancestor; |
1253 ancestor = ancestor->parentItem(); |
1351 ancestor = ancestor->parentItem(); |
1254 } |
1352 } |
1255 bool foundRoot = false; |
1353 |
1256 QModelIndex index; |
1354 CssInspectorModel *model = static_cast<CssInspectorModel*>(mTreeView->model()); |
1257 for (int i=ancestorItems.count() -1; i>=0; i--) { |
1355 // Find root element |
1258 const QGraphicsItem *thisItem = ancestorItems.at(i); |
1356 int rootItemIndex = 0; // This is used later (outside for loop) |
1259 if (!foundRoot) { |
1357 bool rootIsInScreen = false; |
1260 const QGraphicsWidget *wid = static_cast<const QGraphicsWidget*>(thisItem); |
1358 |
1261 if (wid) { |
1359 // Iterating forwards in a reverse containment-order list |
1262 QString name = wid->metaObject()->className(); |
1360 for (; rootItemIndex < ancestorItems.count(); ++rootItemIndex) { |
1263 if (name == "HbScreen") { |
1361 const QGraphicsItem *thisItem = ancestorItems.at(rootItemIndex); |
1264 foundRoot = true; |
1362 const QGraphicsWidget *widget = static_cast<const QGraphicsWidget*>(thisItem); |
|
1363 if (widget) { |
|
1364 if (widget->metaObject()->className() == ROOT_TREE_ELEMENT) { |
|
1365 rootIsInScreen = true; |
|
1366 break; |
|
1367 } |
|
1368 } |
|
1369 } |
|
1370 // Get the correct window |
|
1371 QModelIndex parentIndex; |
|
1372 bool foundWindow = false; |
|
1373 int winCount = model->rowCount(QModelIndex()); |
|
1374 const HbWidget *hbWidget = static_cast<const HbWidget*>(item); |
|
1375 if (hbWidget) { |
|
1376 for (int idx=0; idx<winCount; idx++) { |
|
1377 parentIndex = model->index(idx, 0, QModelIndex()); |
|
1378 CssInspectorModelItem *modelItem = static_cast<CssInspectorModelItem*>(parentIndex.internalPointer()); |
|
1379 if (modelItem->data()->window() == hbWidget->mainWindow()) { |
|
1380 foundWindow = true; |
|
1381 break; |
|
1382 } |
|
1383 } |
|
1384 } |
|
1385 |
|
1386 if (foundWindow) { |
|
1387 if (!rootIsInScreen) { |
|
1388 // Need to set parentIndex to popupmgr |
|
1389 parentIndex = model->index(model->rowCount(parentIndex)-1, 0, parentIndex); |
|
1390 rootItemIndex--; |
|
1391 } |
|
1392 // Now descend containment heirarchy getting index |
|
1393 for (int itemIdx=rootItemIndex; itemIdx>=0; itemIdx--) { |
|
1394 const QGraphicsItem *thisItem = ancestorItems.at(itemIdx); |
|
1395 int rowCount = model->rowCount(parentIndex); |
|
1396 for (int row=0; row<rowCount; row++) { |
|
1397 QModelIndex thisIndex = model->index(row, 0, parentIndex); |
|
1398 CssInspectorModelItem *modelItem = static_cast<CssInspectorModelItem*>(thisIndex.internalPointer()); |
|
1399 QGraphicsItem *gItem = modelItem->data()->graphicsItem(); |
|
1400 if (gItem == thisItem) { |
|
1401 parentIndex = thisIndex; |
|
1402 break; |
1265 } |
1403 } |
1266 } |
1404 } |
1267 } else { |
|
1268 // Find and open tree node for item |
|
1269 CssInspectorModel *model = static_cast<CssInspectorModel*>(mTreeView->model()); |
|
1270 if (model) { |
|
1271 int rowCount = model->rowCount(index); |
|
1272 for (int row=0; row<rowCount; row++) { |
|
1273 QModelIndex idx = model->index(row, 0, index); |
|
1274 CssInspectorModelItem *modelItem = static_cast<CssInspectorModelItem*>(idx.internalPointer()); |
|
1275 QGraphicsItem *graphicsItem = modelItem->data(); |
|
1276 if (graphicsItem == thisItem) { |
|
1277 index = idx; |
|
1278 break; |
|
1279 } |
|
1280 } |
|
1281 } |
|
1282 } |
1405 } |
1283 } |
1406 } |
1284 mTreeView->collapseAll(); |
1407 mTreeView->collapseAll(); |
1285 mTreeView->scrollTo(index, QAbstractItemView::EnsureVisible); |
1408 mTreeView->scrollTo(parentIndex, QAbstractItemView::EnsureVisible); |
1286 mTreeView->expand(index); |
1409 mTreeView->expand(parentIndex); |
1287 |
1410 |
1288 } else { |
1411 } else { |
1289 mWidgetMLBox->setText(""); |
1412 mWidgetMLBox->setText(""); |
1290 mLayoutCssBox->setText(""); |
1413 mLayoutCssBox->setText(""); |
1291 mColorsCssBox->setText(""); |
1414 mColorsCssBox->setText(""); |
1292 mPathLabel->setText(""); |
1415 mPathLabel->setText(""); |
1293 mSizeHintLabel->setText(""); |
1416 mSizeHintLabel->setText(""); |
1294 mSizePolicyHoriz->setText(""); |
1417 mSizePolicyHoriz->setText(""); |
1295 mSizePolicyVert->setText(""); |
1418 mSizePolicyVert->setText(""); |
|
1419 mTreeView->collapseAll(); |
1296 } |
1420 } |
1297 } |
1421 } |
1298 |
1422 |
1299 |
1423 |
1300 |
1424 |