detailed info: modified table width to contents
authorsungmin ha <sungmin82.ha@samsung.com>
Thu, 26 Mar 2015 04:30:35 +0000 (13:30 +0900)
committersungmin ha <sungmin82.ha@samsung.com>
Thu, 26 Mar 2015 07:19:19 +0000 (16:19 +0900)
Change-Id: I8c7f9616ebf328916b96f42830ffc530b01bcbf3
Signed-off-by: sungmin ha <sungmin82.ha@samsung.com>
tizen/src/ui/menu/detailedinfodialog.cpp
tizen/src/ui/menu/detailedinfodialog.h

index ecc7084fff3a95b40c95648d60fee97d29795bb2..9cbe2db80ae47ee6b5975b33b9484ec77cbf9655 100644 (file)
@@ -54,7 +54,7 @@ DetailedInfoDialog::DetailedInfoDialog(QWidget *parent) :
     upsideLayout->setSpacing(0);
 
     /* tab */
-    QTabWidget *tabWidget = new QTabWidget(this);
+    tabWidget = new QTabWidget(this);
     QWidget *vmInfo = new QWidget;
     QWidget *shortcutInfo = new QWidget;
     tabWidget->addTab(vmInfo, tr("VM Info"));
@@ -65,16 +65,23 @@ DetailedInfoDialog::DetailedInfoDialog(QWidget *parent) :
     vmInfoTable->setColumnCount(2);
     vmInfoTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
     vmInfoTable->setAlternatingRowColors(true);
-
     vmInfoTable->verticalHeader()->hide();
-    vmInfoTable->resizeRowsToContents();
-    vmInfoTable->horizontalHeader()->setStretchLastSection(true);
-    vmInfoTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
 
     QStringList header;
     header << "Feature" << "Value";
     vmInfoTable->setHorizontalHeaderLabels(header);
 
+    /* shortcut info table */
+    shortcutInfoTable = new QTableWidget(shortcutInfo);
+    shortcutInfoTable->setColumnCount(2);
+    shortcutInfoTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+    shortcutInfoTable->setAlternatingRowColors(true);
+    shortcutInfoTable->verticalHeader()->hide();
+
+    header.clear();
+    header << "Function" << "Key sequence";
+    shortcutInfoTable->setHorizontalHeaderLabels(header);
+
     /* table items */
     int index = 0;
     setDataTable(vmInfoTable, "VM Name", win->uiInfo->vmName, index++);
@@ -110,28 +117,13 @@ DetailedInfoDialog::DetailedInfoDialog(QWidget *parent) :
 
     int tableHeight = vmInfoTable->horizontalHeader()->height();
     for (int i = 0; i < vmInfoTable->rowCount(); i++) {
-            tableHeight += vmInfoTable->rowHeight(i);
+        tableHeight += vmInfoTable->rowHeight(i);
     }
-    vmInfoTable->setMinimumWidth(200);
-    vmInfoTable->setMinimumHeight(tableHeight + 2/*border*/);
+    vmInfoTable->setMinimumHeight(tableHeight + TABLE_BORDER_SIZE);
+    shortcutInfoTable->setMinimumHeight(tableHeight + TABLE_BORDER_SIZE);
 
-    /* shortcut info table */
-    shortcutInfoTable = new QTableWidget(shortcutInfo);
-    shortcutInfoTable->setColumnCount(2);
-    shortcutInfoTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
-    shortcutInfoTable->setAlternatingRowColors(true);
-
-    shortcutInfoTable->verticalHeader()->hide();
-    shortcutInfoTable->horizontalHeader()->setStretchLastSection(true);
-    shortcutInfoTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
-    shortcutInfoTable->setMinimumHeight(tableHeight + 2);
-
-    header.clear();
-    header << "Function" << "Key sequence";
-    shortcutInfoTable->setHorizontalHeaderLabels(header);
-
-    tabWidget->setMinimumWidth(vmInfoTable->width() + 60);
-    tabWidget->setMinimumHeight(vmInfoTable->height() + 30);
+    QSize tabSize = tabWidget->tabBar()->sizeHint();
+    tabWidget->setMinimumHeight(vmInfoTable->height() + tabSize.height() + TABLE_BORDER_SIZE);
 
     upsideLayout->addWidget(tabWidget);
 
@@ -166,6 +158,24 @@ void DetailedInfoDialog::setDataTable(QTableWidget* table, QString key, QString
     table->setItem(index, 0, item);
     item = new QTableWidgetItem(value);
     table->setItem(index, 1, item);
+
+    resizeTableWidth();
+}
+
+void DetailedInfoDialog::resizeTableWidth()
+{
+    vmInfoTable->resizeColumnsToContents();
+    shortcutInfoTable->resizeColumnsToContents();
+
+    QSize scrollBarSize = shortcutInfoTable->verticalScrollBar()->sizeHint();
+    int vtWidth = vmInfoTable->columnWidth(0) + vmInfoTable->columnWidth(1) + TABLE_BORDER_SIZE;
+    int stWidth = shortcutInfoTable->columnWidth(0) + shortcutInfoTable->columnWidth(1)
+                                                    + scrollBarSize.width() + TABLE_BORDER_SIZE;
+    int tableMinWidth = (vtWidth > stWidth) ? vtWidth : stWidth;
+
+    vmInfoTable->setMinimumWidth(tableMinWidth);
+    shortcutInfoTable->setMinimumWidth(tableMinWidth);
+    tabWidget->setMinimumWidth(tableMinWidth + TAB_BORDER_SIZE);
 }
 
 void DetailedInfoDialog::removeDataTable(QTableWidget* table, int startIndex, int lastIndex)
@@ -242,6 +252,9 @@ void DetailedInfoDialog::showEvent(QShowEvent *event)
     setShortcutInfoTable(keyboardShortcut->getPopupMenuShortcutMap());
     setShortcutInfoTable(keyboardShortcut->getHwKeyShortcutMap());
     setShortcutInfoTable(keyboardShortcut->getControllerShortcutMap());
+
+    vmInfoTable->horizontalHeader()->setStretchLastSection(true);
+    shortcutInfoTable->horizontalHeader()->setStretchLastSection(true);
 }
 
 QTableWidget *DetailedInfoDialog::getShortcutInfoTable()
index c63b114a32fdf4c988e90265e36b56a46f083d10..cd65f6f79758f758d2cd767d7071d719155b8456 100644 (file)
@@ -36,6 +36,8 @@
 #include "keyboardshortcut.h"
 
 #define DETAILED_INFO_TITLE "Detailed Info"
+#define TABLE_BORDER_SIZE 2
+#define TAB_BORDER_SIZE 4
 
 class DetailedInfoDialog : public QDialog
 {
@@ -57,6 +59,7 @@ public slots:
     void slotDoubleClicked(int nRow, int nCol);
 
 private:
+    void resizeTableWidth();
     QStringList getImagePathList();
     QVBoxLayout *baseLayout;
     QHBoxLayout *upsideLayout;
@@ -66,6 +69,7 @@ private:
     QHBoxLayout *downsideLayout;
     QPushButton *okBtn;
     KeyboardShortcut* keyboardShortcut;
+    QTabWidget *tabWidget;
 };
 
 #endif // DETAILEDINFODIALOG_H