Skip to content

Commit

Permalink
Cleanup font appearance and alignment
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Oct 29, 2024
1 parent c4df3d7 commit a62901a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
23 changes: 17 additions & 6 deletions avogadro/qtplugins/molecularproperties/molecularmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ int MolecularModel::rowCount(const QModelIndex& parent) const

const auto& properties = m_molecule->dataMap();
rows += properties.names().size(); // 0 or more
// if "name" is in the properties, we don't need it twice
if (properties.hasValue("name"))
--rows;

return rows;
}
Expand Down Expand Up @@ -212,7 +215,7 @@ QVariant MolecularModel::data(const QModelIndex& index, int role) const

// handle text alignments
if (role == Qt::TextAlignmentRole) {
return toVariant(Qt::AlignHCenter | Qt::AlignRight);
return toVariant(Qt::AlignRight);
}

if (role != Qt::UserRole && role != Qt::DisplayRole && role != Qt::EditRole)
Expand Down Expand Up @@ -251,6 +254,9 @@ QVariant MolecularModel::data(const QModelIndex& index, int role) const
const auto map = m_molecule->dataMap();
auto it = map.begin();
std::advance(it, offset);
if (it->first == "name")
std::advance(it, 1); // skip the name if it's in the properties

if (it != map.end()) {
return QString::fromStdString(it->second.toString());
}
Expand All @@ -261,21 +267,24 @@ QVariant MolecularModel::data(const QModelIndex& index, int role) const
QVariant MolecularModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
// Simple lambda to convert QFlags to variant as in Qt 6 this needs help.
auto toVariant = [&](auto flags) {
return static_cast<Qt::Alignment::Int>(flags);
};

// handle text alignments
if (role == Qt::TextAlignmentRole) {
if (orientation == Qt::Vertical) {
return Qt::AlignHCenter; // XYZ coordinates
return toVariant(Qt::AlignLeft);
}
return toVariant(Qt::AlignHCenter);
}

if (role != Qt::DisplayRole)
return QVariant();

if (orientation == Qt::Horizontal) {
if (section == 0)
return tr("Property");
else if (section == 1)
return tr("Value");
return tr("Property");
} else if (orientation == Qt::Vertical) {
if (section == Name)
return tr("Molecule Name");
Expand Down Expand Up @@ -309,6 +318,8 @@ QVariant MolecularModel::headerData(int section, Qt::Orientation orientation,
const auto map = m_molecule->dataMap();
auto it = map.begin();
std::advance(it, offset);
if (it->first == "name")
std::advance(it, 1); // skip the name if it's in the properties
if (it != map.end()) {
return QString::fromStdString(it->first);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ void MolecularProperties::showDialog()
view->setSourceModel(model);
view->setModel(model);

// set the headers to true
QFont font = view->horizontalHeader()->font();
font.setBold(true);
view->horizontalHeader()->setFont(font);
view->verticalHeader()->setFont(font);

view->setItemDelegateForColumn(0, new RichTextDelegate(view));

view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->horizontalHeader()->setStretchLastSection(true);
view->resizeColumnsToContents();

layout->addWidget(view);
Expand Down
3 changes: 0 additions & 3 deletions avogadro/qtplugins/molecularproperties/molecularview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ MolecularView::MolecularView(QWidget* parent)

QHeaderView* horizontal = this->horizontalHeader();
horizontal->setSectionResizeMode(QHeaderView::Interactive);
horizontal->setMinimumSectionSize(75);
QHeaderView* vertical = this->verticalHeader();
vertical->setSectionResizeMode(QHeaderView::Interactive);
vertical->setMinimumSectionSize(30);
vertical->setDefaultAlignment(Qt::AlignCenter);

// You can select everything (e.g., to copy, select all, etc.)
setCornerButtonEnabled(true);
Expand Down

0 comments on commit a62901a

Please sign in to comment.