ctkCheckableHeaderView.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. /*=========================================================================
  15. Program: ParaView
  16. Module: $RCSfile: pqCheckableHeaderView.cxx,v $
  17. Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
  18. All rights reserved.
  19. ParaView is a free software; you can redistribute it and/or modify it
  20. under the terms of the ParaView license version 1.2.
  21. See License_v1.2.txt for the full ParaView license.
  22. A copy of this license can be obtained by contacting
  23. Kitware Inc.
  24. 28 Corporate Drive
  25. Clifton Park, NY 12065
  26. USA
  27. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
  31. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. =========================================================================*/
  39. // Qt includes
  40. #include <QAbstractItemModel>
  41. #include <QApplication>
  42. #include <QDebug>
  43. #include <QEvent>
  44. #include <QList>
  45. #include <QMouseEvent>
  46. #include <QPainter>
  47. #include <QPixmap>
  48. #include <QStyle>
  49. // CTK includes
  50. #include "ctkCheckableHeaderView.h"
  51. #include "ctkCheckBoxPixmaps.h"
  52. //-----------------------------------------------------------------------------
  53. class ctkCheckableHeaderViewPrivate
  54. {
  55. Q_DECLARE_PUBLIC(ctkCheckableHeaderView);
  56. protected:
  57. ctkCheckableHeaderView* const q_ptr;
  58. public:
  59. ctkCheckableHeaderViewPrivate(ctkCheckableHeaderView& object);
  60. ~ctkCheckableHeaderViewPrivate();
  61. void init();
  62. int Pressed;
  63. ctkCheckBoxPixmaps* CheckBoxPixmaps;
  64. bool HeaderIsUpdating;
  65. bool ItemsAreUpdating;
  66. bool PropagateToItems;
  67. };
  68. //----------------------------------------------------------------------------
  69. ctkCheckableHeaderViewPrivate::ctkCheckableHeaderViewPrivate(ctkCheckableHeaderView& object)
  70. :q_ptr(&object)
  71. {
  72. this->HeaderIsUpdating = false;
  73. this->ItemsAreUpdating = false;
  74. this->CheckBoxPixmaps = 0;
  75. this->Pressed = -1;
  76. this->PropagateToItems = true;
  77. }
  78. //-----------------------------------------------------------------------------
  79. ctkCheckableHeaderViewPrivate::~ctkCheckableHeaderViewPrivate()
  80. {
  81. if (this->CheckBoxPixmaps)
  82. {
  83. delete this->CheckBoxPixmaps;
  84. this->CheckBoxPixmaps = 0;
  85. }
  86. }
  87. //----------------------------------------------------------------------------
  88. void ctkCheckableHeaderViewPrivate::init()
  89. {
  90. Q_Q(ctkCheckableHeaderView);
  91. this->CheckBoxPixmaps = new ctkCheckBoxPixmaps(q);
  92. }
  93. //----------------------------------------------------------------------------
  94. ctkCheckableHeaderView::ctkCheckableHeaderView(
  95. Qt::Orientation orient, QWidget *widgetParent)
  96. : QHeaderView(orient, widgetParent)
  97. , d_ptr(new ctkCheckableHeaderViewPrivate(*this))
  98. {
  99. Q_D(ctkCheckableHeaderView);
  100. d->init();
  101. if(widgetParent)
  102. {
  103. // Listen for focus change events.
  104. widgetParent->installEventFilter(this);
  105. }
  106. }
  107. //-----------------------------------------------------------------------------
  108. ctkCheckableHeaderView::~ctkCheckableHeaderView()
  109. {
  110. }
  111. //-----------------------------------------------------------------------------
  112. bool ctkCheckableHeaderView::eventFilter(QObject *, QEvent *e)
  113. {
  114. if(e->type() != QEvent::FocusIn &&
  115. e->type() != QEvent::FocusOut)
  116. {
  117. return false;
  118. }
  119. this->updateHeaders();
  120. return false;
  121. }
  122. //-----------------------------------------------------------------------------
  123. void ctkCheckableHeaderView::setModel(QAbstractItemModel *newModel)
  124. {
  125. Q_D(ctkCheckableHeaderView);
  126. QAbstractItemModel *current = this->model();
  127. if (current == newModel)
  128. {
  129. return;
  130. }
  131. if(current)
  132. {
  133. this->disconnect(
  134. current, SIGNAL(headerDataChanged(Qt::Orientation, int, int)),
  135. this, SLOT(updateHeaderData(Qt::Orientation, int, int)));
  136. this->disconnect(
  137. current, SIGNAL(modelReset()),
  138. this, SLOT(updateHeaders()));
  139. this->disconnect(
  140. current, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
  141. this, SLOT(updateHeadersFromItems(const QModelIndex&, const QModelIndex&)));
  142. this->disconnect(
  143. current, SIGNAL(columnsInserted(const QModelIndex &, int, int)),
  144. this, SLOT(insertHeaderSection(const QModelIndex &, int, int)));
  145. this->disconnect(
  146. current, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
  147. this, SLOT(insertHeaderSection(const QModelIndex &, int, int)));
  148. }
  149. this->QHeaderView::setModel(newModel);
  150. if(newModel)
  151. {
  152. this->connect(
  153. newModel, SIGNAL(headerDataChanged(Qt::Orientation, int, int)),
  154. this, SLOT(updateHeaderData(Qt::Orientation, int, int)));
  155. this->connect(
  156. newModel, SIGNAL(modelReset()),
  157. this, SLOT(updateHeaders()));
  158. if (d->PropagateToItems)
  159. {
  160. this->connect(
  161. newModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
  162. this, SLOT(updateHeadersFromItems(const QModelIndex&, const QModelIndex&)));
  163. }
  164. if(this->orientation() == Qt::Horizontal)
  165. {
  166. this->connect(
  167. newModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)),
  168. this, SLOT(insertHeaderSection(const QModelIndex &, int, int)));
  169. }
  170. else
  171. {
  172. this->connect(
  173. newModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
  174. this, SLOT(insertHeaderSection(const QModelIndex &, int, int)));
  175. }
  176. }
  177. // Determine which sections are clickable and setup the icons.
  178. this->updateHeaders();
  179. }
  180. //-----------------------------------------------------------------------------
  181. void ctkCheckableHeaderView::setRootIndex(const QModelIndex &index)
  182. {
  183. this->QHeaderView::setRootIndex(index);
  184. this->updateHeaders();
  185. }
  186. //-----------------------------------------------------------------------------
  187. void ctkCheckableHeaderView::setPropagateToItems(bool propagate)
  188. {
  189. Q_D(ctkCheckableHeaderView);
  190. if (d->PropagateToItems == propagate)
  191. {
  192. return;
  193. }
  194. d->PropagateToItems = propagate;
  195. if (!this->model())
  196. {
  197. return;
  198. }
  199. if (propagate)
  200. {
  201. this->connect(
  202. this->model(), SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
  203. this, SLOT(updateHeadersFromItems(const QModelIndex&, const QModelIndex&)));
  204. this->updateHeadersFromItems();
  205. }
  206. else
  207. {
  208. this->disconnect(
  209. this->model(), SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
  210. this, SLOT(updateHeadersFromItems(const QModelIndex&, const QModelIndex&)));
  211. }
  212. }
  213. //-----------------------------------------------------------------------------
  214. bool ctkCheckableHeaderView::propagateToItems()const
  215. {
  216. Q_D(const ctkCheckableHeaderView);
  217. return d->PropagateToItems;
  218. }
  219. //-----------------------------------------------------------------------------
  220. void ctkCheckableHeaderView::toggleCheckState(int section)
  221. {
  222. // If the section is checkable, toggle the check state.
  223. if(!this->isCheckable(section))
  224. {
  225. return;
  226. }
  227. // I've no strong feeling to turn the state checked or unchecked when the
  228. // state is PartiallyChecked.
  229. this->setCheckState(section, this->checkState(section) == Qt::Checked ? Qt::Unchecked : Qt::Checked);
  230. }
  231. //-----------------------------------------------------------------------------
  232. void ctkCheckableHeaderView::setCheckState(int section, Qt::CheckState checkState)
  233. {
  234. // If the section is checkable, toggle the check state.
  235. QAbstractItemModel *current = this->model();
  236. if(current == 0)
  237. {
  238. return;
  239. }
  240. // If the state is unchecked or partially checked, the state
  241. // should be changed to checked.
  242. current->setHeaderData(section, this->orientation(),
  243. checkState, Qt::CheckStateRole);
  244. }
  245. //-----------------------------------------------------------------------------
  246. void ctkCheckableHeaderView::updateHeaderData(Qt::Orientation orient,
  247. int firstSection,
  248. int lastSection)
  249. {
  250. if(orient != this->orientation())
  251. {
  252. return;
  253. }
  254. this->updateHeaders(firstSection, lastSection);
  255. }
  256. //-----------------------------------------------------------------------------
  257. void ctkCheckableHeaderView::updateHeaders(int firstSection, int lastSection)
  258. {
  259. Q_D(ctkCheckableHeaderView);
  260. if(d->HeaderIsUpdating)
  261. {
  262. return;
  263. }
  264. d->HeaderIsUpdating = true;
  265. QAbstractItemModel *current = this->model();
  266. Q_ASSERT(current);
  267. firstSection = qBound(0, firstSection, this->count() -1);
  268. lastSection = qBound(0, lastSection, this->count() -1);
  269. bool active = true;
  270. if(this->parentWidget())
  271. {
  272. active = this->parentWidget()->hasFocus();
  273. }
  274. int maxJ = this->orientation() == Qt::Horizontal ?
  275. current->rowCount() : current->columnCount();
  276. for(int i = firstSection; i <= lastSection; i++)
  277. {
  278. QVariant decoration;
  279. Qt::CheckState checkState;
  280. if (this->checkState(i, checkState))
  281. {
  282. decoration = d->CheckBoxPixmaps->pixmap(checkState, active);
  283. if (d->PropagateToItems &&
  284. checkState != Qt::PartiallyChecked &&
  285. !d->ItemsAreUpdating)
  286. {
  287. for (int j = 0 ; j < maxJ; ++j)
  288. {
  289. QModelIndex index = this->orientation() == Qt::Horizontal ?
  290. current->index(j, i,this->rootIndex()) :
  291. current->index(i, j,this->rootIndex()) ;
  292. current->setData(index, checkState, Qt::CheckStateRole);
  293. }
  294. }
  295. }
  296. current->setHeaderData(i, this->orientation(), decoration,
  297. Qt::DecorationRole);
  298. }
  299. d->HeaderIsUpdating = false;
  300. }
  301. //-----------------------------------------------------------------------------
  302. void ctkCheckableHeaderView::updateHeadersFromItems()
  303. {
  304. QAbstractItemModel *currentModel = this->model();
  305. if (!currentModel)
  306. {
  307. return;
  308. }
  309. QModelIndex firstIndex = currentModel->index(0,0);
  310. QModelIndex lastIndex =
  311. currentModel->index(currentModel->rowCount() - 1,
  312. currentModel->columnCount() -1);
  313. this->updateHeadersFromItems(firstIndex, lastIndex);
  314. }
  315. //-----------------------------------------------------------------------------
  316. void ctkCheckableHeaderView::updateHeadersFromItems(const QModelIndex & topLeft,
  317. const QModelIndex & bottomRight)
  318. {
  319. Q_UNUSED(bottomRight);
  320. Q_D(ctkCheckableHeaderView);
  321. if(d->ItemsAreUpdating || !d->PropagateToItems ||
  322. topLeft.parent() != this->rootIndex())
  323. {
  324. return;
  325. }
  326. d->ItemsAreUpdating = true;
  327. QAbstractItemModel *current = this->model();
  328. Q_ASSERT(current);
  329. int lastI;
  330. int lastJ;
  331. if (this->orientation() == Qt::Horizontal)
  332. {
  333. lastI = this->count();
  334. lastJ = current->rowCount();
  335. }
  336. else
  337. {
  338. lastI = this->count();
  339. lastJ = current->columnCount();
  340. }
  341. for(int i = 0; i <= lastI; ++i)
  342. {
  343. Qt::CheckState sectionState;
  344. if (!this->checkState(i, sectionState))
  345. {
  346. continue;
  347. }
  348. bool itemIsCheckable = false;
  349. // get the first item state
  350. Qt::CheckState itemsState;
  351. int j = 0;
  352. for ( ; j <= lastJ; ++j)
  353. {
  354. QModelIndex index = this->orientation() == Qt::Horizontal ?
  355. current->index(j, i, topLeft.parent()) :
  356. current->index(i, j, topLeft.parent());
  357. itemsState = static_cast<Qt::CheckState>(
  358. index.data(Qt::CheckStateRole).toInt(&itemIsCheckable));
  359. if (itemIsCheckable)
  360. {
  361. break;
  362. }
  363. }
  364. if (j > lastJ)
  365. {// the first item check state couldn't be found
  366. continue;
  367. }
  368. // check the other states to make sure it is the same state
  369. for (; j <= lastJ; ++j)
  370. {
  371. QModelIndex index = this->orientation() == Qt::Horizontal ?
  372. current->index(j, i, topLeft.parent()) :
  373. current->index(i, j, topLeft.parent());
  374. Qt::CheckState itemState =
  375. static_cast<Qt::CheckState>(index.data(Qt::CheckStateRole).toInt(&itemIsCheckable));
  376. if (itemIsCheckable && itemState!= itemsState)
  377. {// there is at least 1 item with a different state
  378. this->setCheckState(i, Qt::PartiallyChecked);
  379. break;
  380. }
  381. }
  382. if (j > lastJ)
  383. {
  384. this->setCheckState(i, itemsState);
  385. }
  386. }
  387. d->ItemsAreUpdating = false;
  388. }
  389. //-----------------------------------------------------------------------------
  390. void ctkCheckableHeaderView::insertHeaderSection(const QModelIndex &parentIndex,
  391. int first, int last)
  392. {
  393. if (this->rootIndex() != parentIndex)
  394. {
  395. return;
  396. }
  397. this->updateHeaders(first, last);
  398. }
  399. //-----------------------------------------------------------------------------
  400. bool ctkCheckableHeaderView::isCheckable(int section)const
  401. {
  402. return !this->model()->headerData(section, this->orientation(), Qt::CheckStateRole).isNull();
  403. }
  404. //-----------------------------------------------------------------------------
  405. Qt::CheckState ctkCheckableHeaderView::checkState(int section)const
  406. {
  407. return static_cast<Qt::CheckState>(
  408. this->model()->headerData(section, this->orientation(), Qt::CheckStateRole).toInt());
  409. }
  410. //-----------------------------------------------------------------------------
  411. bool ctkCheckableHeaderView::checkState(int section, Qt::CheckState& checkState)const
  412. {
  413. bool checkable = false;
  414. checkState = static_cast<Qt::CheckState>(
  415. this->model()->headerData(section, this->orientation(), Qt::CheckStateRole).toInt(&checkable));
  416. return checkable;
  417. }
  418. //-----------------------------------------------------------------------------
  419. void ctkCheckableHeaderView::mousePressEvent(QMouseEvent *e)
  420. {
  421. Q_D(ctkCheckableHeaderView);
  422. if (e->button() != Qt::LeftButton ||
  423. d->Pressed >= 0)
  424. {
  425. d->Pressed = -1;
  426. this->QHeaderView::mousePressEvent(e);
  427. return;
  428. }
  429. d->Pressed = -1;
  430. //check if the check box is pressed
  431. int pos = this->orientation() == Qt::Horizontal ? e->x() : e->y();
  432. int section = this->logicalIndexAt(pos);
  433. if (this->isCheckable(section) &&
  434. this->isPointInCheckBox(section, e->pos()))
  435. {
  436. d->Pressed = section;
  437. }
  438. this->QHeaderView::mousePressEvent(e);
  439. }
  440. //-----------------------------------------------------------------------------
  441. void ctkCheckableHeaderView::mouseReleaseEvent(QMouseEvent *e)
  442. {
  443. Q_D(ctkCheckableHeaderView);
  444. if (e->button() != Qt::LeftButton ||
  445. d->Pressed < 0)
  446. {
  447. d->Pressed = -1;
  448. this->QHeaderView::mouseReleaseEvent(e);
  449. return;
  450. }
  451. //check if the check box is pressed
  452. int pos = this->orientation() == Qt::Horizontal ? e->x() : e->y();
  453. int section = this->logicalIndexAt(pos);
  454. if (section == d->Pressed &&
  455. this->isPointInCheckBox(section, e->pos()))
  456. {
  457. d->Pressed = -1;
  458. this->toggleCheckState(section);
  459. }
  460. this->QHeaderView::mousePressEvent(e);
  461. }
  462. //-----------------------------------------------------------------------------
  463. bool ctkCheckableHeaderView::isPointInCheckBox(int section, QPoint pos)const
  464. {
  465. QRect sectionRect = this->orientation() == Qt::Horizontal ?
  466. QRect(this->sectionPosition(section), 0,
  467. this->sectionSize(section), this->height()):
  468. QRect(0, this->sectionPosition(section),
  469. this->width(), this->sectionSize(section));
  470. QStyleOptionHeader opt;
  471. this->initStyleOption(&opt);
  472. this->initStyleSectionOption(&opt, section, sectionRect);
  473. QRect headerLabelRect = this->style()->subElementRect(QStyle::SE_HeaderLabel, &opt, this);
  474. // from qcommonstyle.cpp:1541
  475. if (opt.icon.isNull())
  476. {
  477. return false;
  478. }
  479. QPixmap pixmap
  480. = opt.icon.pixmap(this->style()->pixelMetric(QStyle::PM_SmallIconSize),
  481. (opt.state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled);
  482. QRect aligned = this->style()->alignedRect(opt.direction, QFlag(opt.iconAlignment),
  483. pixmap.size(), headerLabelRect);
  484. QRect inter = aligned.intersected(headerLabelRect);
  485. return inter.contains(pos);
  486. }
  487. //-----------------------------------------------------------------------------
  488. void ctkCheckableHeaderView::initStyleSectionOption(QStyleOptionHeader *option, int section, QRect rect)const
  489. {
  490. // from qheaderview.cpp:paintsection
  491. QStyle::State state = QStyle::State_None;
  492. if (this->isEnabled())
  493. {
  494. state |= QStyle::State_Enabled;
  495. }
  496. if (this->window()->isActiveWindow())
  497. {
  498. state |= QStyle::State_Active;
  499. }
  500. if (this->isSortIndicatorShown() &&
  501. this->sortIndicatorSection() == section)
  502. {
  503. option->sortIndicator = (this->sortIndicatorOrder() == Qt::AscendingOrder)
  504. ? QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp;
  505. }
  506. // setup the style option structure
  507. QVariant textAlignment =
  508. this->model()->headerData(section, this->orientation(),
  509. Qt::TextAlignmentRole);
  510. option->rect = rect;
  511. option->section = section;
  512. option->state |= state;
  513. option->textAlignment = Qt::Alignment(textAlignment.isValid()
  514. ? Qt::Alignment(textAlignment.toInt())
  515. : this->defaultAlignment());
  516. option->iconAlignment = Qt::AlignVCenter;
  517. option->text = this->model()->headerData(section, this->orientation(),
  518. Qt::DisplayRole).toString();
  519. if (this->textElideMode() != Qt::ElideNone)
  520. {
  521. option->text = option->fontMetrics.elidedText(option->text, this->textElideMode() , rect.width() - 4);
  522. }
  523. QVariant variant = this->model()->headerData(section, this->orientation(),
  524. Qt::DecorationRole);
  525. option->icon = qvariant_cast<QIcon>(variant);
  526. if (option->icon.isNull())
  527. {
  528. option->icon = qvariant_cast<QPixmap>(variant);
  529. }
  530. QVariant foregroundBrush = this->model()->headerData(section, this->orientation(),
  531. Qt::ForegroundRole);
  532. if (qVariantCanConvert<QBrush>(foregroundBrush))
  533. {
  534. option->palette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(foregroundBrush));
  535. }
  536. //QPointF oldBO = painter->brushOrigin();
  537. QVariant backgroundBrush = this->model()->headerData(section, this->orientation(),
  538. Qt::BackgroundRole);
  539. if (qVariantCanConvert<QBrush>(backgroundBrush))
  540. {
  541. option->palette.setBrush(QPalette::Button, qvariant_cast<QBrush>(backgroundBrush));
  542. option->palette.setBrush(QPalette::Window, qvariant_cast<QBrush>(backgroundBrush));
  543. //painter->setBrushOrigin(option->rect.topLeft());
  544. }
  545. // the section position
  546. int visual = this->visualIndex(section);
  547. Q_ASSERT(visual != -1);
  548. if (this->count() == 1)
  549. {
  550. option->position = QStyleOptionHeader::OnlyOneSection;
  551. }
  552. else if (visual == 0)
  553. {
  554. option->position = QStyleOptionHeader::Beginning;
  555. }
  556. else if (visual == this->count() - 1)
  557. {
  558. option->position = QStyleOptionHeader::End;
  559. }
  560. else
  561. {
  562. option->position = QStyleOptionHeader::Middle;
  563. }
  564. option->orientation = this->orientation();
  565. /* the selected position
  566. bool previousSelected = d->isSectionSelected(this->logicalIndex(visual - 1));
  567. bool nextSelected = d->isSectionSelected(this->logicalIndex(visual + 1));
  568. if (previousSelected && nextSelected)
  569. option->selectedPosition = QStyleOptionHeader::NextAndPreviousAreSelected;
  570. else if (previousSelected)
  571. option->selectedPosition = QStyleOptionHeader::PreviousIsSelected;
  572. else if (nextSelected)
  573. option->selectedPosition = QStyleOptionHeader::NextIsSelected;
  574. else
  575. option->selectedPosition = QStyleOptionHeader::NotAdjacent;
  576. */
  577. }