VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIBootTable.cpp@ 35740

Last change on this file since 35740 was 34614, checked in by vboxsync, 14 years ago

FE/Qt: Warning fix for UIBootTable.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 4.7 KB
Line 
1/* $Id: UIBootTable.cpp 34614 2010-12-02 14:09:47Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt4 GUI ("VirtualBox"):
5 * UIBootTable class implementation
6 */
7
8/*
9 * Copyright (C) 2009 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20/* Global include */
21#include <QScrollBar>
22
23/* Local includes */
24#include "UIBootTable.h"
25#include "VBoxGlobal.h"
26
27UIBootTableItem::UIBootTableItem(KDeviceType type)
28 : m_type(type)
29{
30 setCheckState(Qt::Unchecked);
31 switch(type)
32 {
33 case KDeviceType_Floppy:
34 {
35 setIcon(QIcon(":fd_16px.png"));
36 break;
37 }
38 case KDeviceType_DVD:
39 {
40 setIcon(QIcon(":cd_16px.png"));
41 break;
42 }
43 case KDeviceType_HardDisk:
44 {
45 setIcon(QIcon(":hd_16px.png"));
46 break;
47 }
48 case KDeviceType_Network:
49 {
50 setIcon(QIcon(":nw_16px.png"));
51 break;
52 }
53 }
54 retranslateUi();
55}
56
57KDeviceType UIBootTableItem::type() const
58{
59 return m_type;
60}
61
62void UIBootTableItem::retranslateUi()
63{
64 setText(vboxGlobal().toString(m_type));
65}
66
67UIBootTable::UIBootTable(QWidget *pParent /* = 0 */)
68 : QIWithRetranslateUI<QListWidget>(pParent)
69{
70 setDragDropMode(QAbstractItemView::InternalMove);
71 setSelectionMode(QAbstractItemView::SingleSelection);
72 setDropIndicatorShown(true);
73 setUniformItemSizes(true);
74 connect(this, SIGNAL(currentRowChanged(int)),
75 this, SIGNAL(sigRowChanged(int)));
76}
77
78void UIBootTable::adjustSizeToFitContent()
79{
80 int h = 2 * frameWidth();
81 int w = h;
82#if QT_VERSION < 0x040700
83# ifdef Q_WS_MAC
84 int left, top, right, bottom;
85 getContentsMargins(&left, &top, &right, &bottom);
86 h += top + bottom;
87 w += left + right;
88# else /* Q_WS_MAC */
89 w += 4;
90# endif /* !Q_WS_MAC */
91#endif /* QT_VERSION < 0x040700 */
92 setFixedSize(sizeHintForColumn(0) + w,
93 sizeHintForRow(0) * count() + h);
94}
95
96void UIBootTable::sltMoveItemUp()
97{
98 QModelIndex index = currentIndex();
99 moveItemTo(index, index.row() - 1);
100}
101
102void UIBootTable::sltMoveItemDown()
103{
104 QModelIndex index = currentIndex();
105 moveItemTo(index, index.row() + 2);
106}
107
108void UIBootTable::retranslateUi()
109{
110 for (int i = 0; i < count(); ++i)
111 static_cast<UIBootTableItem*>(item(i))->retranslateUi();
112
113 adjustSizeToFitContent();
114}
115
116void UIBootTable::dropEvent(QDropEvent *pEvent)
117{
118 QListWidget::dropEvent(pEvent);
119 emit sigRowChanged(currentRow());
120}
121
122QModelIndex UIBootTable::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
123{
124 if (modifiers.testFlag(Qt::ControlModifier))
125 {
126 switch (cursorAction)
127 {
128 case QAbstractItemView::MoveUp:
129 {
130 QModelIndex index = currentIndex();
131 return moveItemTo(index, index.row() - 1);
132 }
133 case QAbstractItemView::MoveDown:
134 {
135 QModelIndex index = currentIndex();
136 return moveItemTo(index, index.row() + 2);
137 }
138 case QAbstractItemView::MovePageUp:
139 {
140 QModelIndex index = currentIndex();
141 return moveItemTo(index, qMax(0, index.row() - verticalScrollBar()->pageStep()));
142 }
143 case QAbstractItemView::MovePageDown:
144 {
145 QModelIndex index = currentIndex();
146 return moveItemTo(index, qMin(model()->rowCount(), index.row() + verticalScrollBar()->pageStep() + 1));
147 }
148 case QAbstractItemView::MoveHome:
149 return moveItemTo(currentIndex(), 0);
150 case QAbstractItemView::MoveEnd:
151 return moveItemTo(currentIndex(), model()->rowCount());
152 default:
153 break;
154 }
155 }
156 return QListWidget::moveCursor(cursorAction, modifiers);
157}
158
159QModelIndex UIBootTable::moveItemTo(const QModelIndex &index, int row)
160{
161 if (!index.isValid())
162 return QModelIndex();
163
164 if (row < 0 || row > model()->rowCount())
165 return QModelIndex();
166
167 QPersistentModelIndex oldIndex(index);
168 UIBootTableItem *pItem = static_cast<UIBootTableItem*>(itemFromIndex(oldIndex));
169 insertItem(row, new UIBootTableItem(*pItem));
170 QPersistentModelIndex newIndex = model()->index(row, 0);
171 delete takeItem(oldIndex.row());
172 setCurrentRow(newIndex.row());
173 return QModelIndex(newIndex);
174}
175
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use