Skip to content

Commit 90ba250

Browse files
committed
Integrate support for Ctrl and Shift modifiers
Signed-off-by: Danilo Aimini <[email protected]>
1 parent 3b6b18e commit 90ba250

File tree

2 files changed

+81
-28
lines changed

2 files changed

+81
-28
lines changed

Code/Framework/AzQtComponents/AzQtComponents/Components/Widgets/AssetFolderThumbnailView.cpp

Lines changed: 80 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,9 @@ namespace AzQtComponents
10711071
}
10721072
else
10731073
{
1074+
// Store previous selection - will be used if key modifiers are being held.
1075+
m_previousSelection = selectionModel()->selection();
1076+
10741077
// Start the updater to only refresh the selection at regular intervals.
10751078
m_selectionUpdater->start(m_selectionUpdateInterval);
10761079

@@ -1099,6 +1102,7 @@ namespace AzQtComponents
10991102

11001103
ClearQueuedMouseEvent();
11011104

1105+
m_previousSelection.clear();
11021106
m_selectionUpdater->stop();
11031107
m_isDragSelectActive = false;
11041108

@@ -1139,7 +1143,38 @@ namespace AzQtComponents
11391143
}
11401144
}
11411145

1142-
selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect);
1146+
switch (QGuiApplication::queryKeyboardModifiers())
1147+
{
1148+
case Qt::ControlModifier:
1149+
{
1150+
selection.merge(m_previousSelection, QItemSelectionModel::ToggleCurrent);
1151+
selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect);
1152+
}
1153+
break;
1154+
1155+
case Qt::ShiftModifier:
1156+
{
1157+
// Replicates behavior in Windows explorer.
1158+
// This will add all newly selected items to the existing selection, but if an item is added
1159+
// to the selection rect and then removed, it will be removed from the previous selection.
1160+
1161+
// Remove new selection from previous selection.
1162+
m_previousSelection.merge(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Current);
1163+
1164+
// Add previous selection to new selection.
1165+
selection.merge(m_previousSelection, QItemSelectionModel::SelectCurrent);
1166+
1167+
// Select both (updated) previous and current selection.
1168+
selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect);
1169+
}
1170+
break;
1171+
1172+
default:
1173+
{
1174+
selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect);
1175+
}
1176+
break;
1177+
}
11431178
}
11441179

11451180
void AssetFolderThumbnailView::ClearQueuedMouseEvent()
@@ -1307,56 +1342,73 @@ namespace AzQtComponents
13071342
return QImage();
13081343
}
13091344

1310-
QRect rect(6, 6, 64, 64);
1311-
QImage dragImage(QRect(0, 0, 70, 70).size(), QImage::Format_ARGB32_Premultiplied);
1312-
QPainter painter(&dragImage);
1313-
1314-
painter.setCompositionMode(QPainter::CompositionMode_Source);
1315-
painter.fillRect(dragImage.rect(), Qt::transparent);
1316-
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
1317-
painter.setOpacity(0.35f);
1318-
painter.fillRect(rect, QColor("#222222"));
1319-
painter.setOpacity(1.0f);
1345+
// Define size of rect for asset/folder icons.
1346+
QRect rect(0, 9, 36, 36);
13201347

1348+
// Generate a drag image of the dragged element.
1349+
// We get the configuration of the first item in the list.
13211350
auto index = indexList.at(0);
1351+
const auto isTopLevel = index.data(static_cast<int>(AssetFolderThumbnailView::Role::IsTopLevel)).value<bool>();
1352+
const auto& config = isTopLevel ? m_config.rootThumbnail : m_config.childThumbnail;
13221353

1354+
// Initialize option
13231355
QStyleOptionViewItem option;
13241356
option.palette = palette();
13251357
option.font = font();
13261358
option.fontMetrics = fontMetrics();
13271359
option.decorationAlignment = Qt::AlignCenter;
13281360
option.rect = rect;
13291361

1330-
// Generate a drag image of the dragged element.
1331-
const auto isTopLevel = index.data(static_cast<int>(AssetFolderThumbnailView::Role::IsTopLevel)).value<bool>();
1362+
// Initialize painter from desired output image.
1363+
QImage dragImage(QRect(0, 0, 44, 56).size(), QImage::Format_ARGB32_Premultiplied);
1364+
QPainter painter(&dragImage);
1365+
painter.setCompositionMode(QPainter::CompositionMode_Source);
1366+
painter.fillRect(dragImage.rect(), Qt::transparent);
1367+
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
13321368

13331369
painter.save();
1334-
painter.setFont(option.font);
13351370

1336-
const auto& config = isTopLevel ? m_config.rootThumbnail : m_config.childThumbnail;
1371+
// Define border color.
1372+
if (selectionModel()->isSelected(index))
1373+
{
1374+
painter.setPen(QPen(config.selectedBorderColor, config.selectedBorderThickness));
1375+
}
1376+
else
1377+
{
1378+
painter.setPen(QPen(config.borderColor, config.borderThickness));
1379+
}
1380+
1381+
// Paint additional rectangles under the top one to signify multiple selection.
1382+
painter.setBrush(QColor("#555")); // TODO - move to const members
1383+
1384+
if (indexList.size() > 2)
1385+
{
1386+
painter.setOpacity(0.5f);
1387+
painter.drawRoundedRect(rect.translated(7, 7), 1, 1); // TODO - move to const members
1388+
}
1389+
1390+
if (indexList.size() > 1)
1391+
{
1392+
painter.setOpacity(1.0f);
1393+
painter.drawRoundedRect(rect.translated(3, 3), 1, 1); // TODO - move to const members
1394+
}
1395+
1396+
// Reset opacity to full.
1397+
painter.setOpacity(1.0f);
1398+
13371399

1338-
const auto borderRadius = config.borderRadius;
1339-
const auto padding = 5;
13401400

13411401
const auto thumbnailRect = rect;
1402+
1403+
const auto padding = 5;
13421404
const auto imageRect = thumbnailRect.adjusted(padding, padding, -padding, -padding);
13431405

13441406
// border
13451407
const auto halfBorderThickness = qMax(config.borderThickness, config.selectedBorderThickness) / 2;
13461408
const auto borderRect =
13471409
QRectF{ thumbnailRect }.adjusted(halfBorderThickness, halfBorderThickness, -halfBorderThickness, -halfBorderThickness);
1348-
QPen borderPen;
1349-
if (option.state & QStyle::State_Selected)
1350-
{
1351-
borderPen = { config.selectedBorderColor, config.selectedBorderThickness };
1352-
}
1353-
else
1354-
{
1355-
borderPen = { config.borderColor, config.borderThickness };
1356-
}
13571410
painter.setBrush(config.backgroundColor);
1358-
painter.setPen(borderPen);
1359-
painter.drawRoundedRect(borderRect, borderRadius, borderRadius);
1411+
painter.drawRoundedRect(borderRect, config.borderRadius, config.borderRadius);
13601412

13611413
// pixmap
13621414
const auto& qVariant = index.data(Qt::DecorationRole);

Code/Framework/AzQtComponents/AzQtComponents/Components/Widgets/AssetFolderThumbnailView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ namespace AzQtComponents
177177

178178
// Selection Handling
179179
void SelectAllEntitiesInSelectionRect();
180+
QItemSelection m_previousSelection;
180181

181182
void ClearQueuedMouseEvent();
182183
void ProcessQueuedMousePressedEvent(QMouseEvent* event);

0 commit comments

Comments
 (0)