vtabindicator.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "vtabindicator.h"
  2. #include <QLabel>
  3. #include <QHBoxLayout>
  4. #include "vedittab.h"
  5. #include "vorphanfile.h"
  6. VTabIndicator::VTabIndicator(QWidget *p_parent)
  7. : QWidget(p_parent)
  8. {
  9. setupUI();
  10. }
  11. void VTabIndicator::setupUI()
  12. {
  13. m_docTypeLabel = new QLabel(this);
  14. m_docTypeLabel->setToolTip(tr("The type of the file"));
  15. m_docTypeLabel->setProperty("ColorGreyLabel", true);
  16. m_readonlyLabel = new QLabel(tr("ReadOnly"), this);
  17. m_readonlyLabel->setToolTip(tr("This file is read-only"));
  18. m_readonlyLabel->setProperty("ColorRedLabel", true);
  19. m_externalLabel = new QLabel(tr("Standalone"), this);
  20. m_externalLabel->setToolTip(tr("This file is not managed by any notebook or folder"));
  21. m_externalLabel->setProperty("ColorTealLabel", true);
  22. m_systemLabel = new QLabel(tr("System"), this);
  23. m_systemLabel->setToolTip(tr("This file is a system file"));
  24. m_systemLabel->setProperty("ColorGreenLabel", true);
  25. m_cursorLabel = new QLabel(this);
  26. QHBoxLayout *mainLayout = new QHBoxLayout(this);
  27. mainLayout->addWidget(m_cursorLabel);
  28. mainLayout->addWidget(m_externalLabel);
  29. mainLayout->addWidget(m_systemLabel);
  30. mainLayout->addWidget(m_readonlyLabel);
  31. mainLayout->addWidget(m_docTypeLabel);
  32. mainLayout->setContentsMargins(0, 0, 0, 0);
  33. setLayout(mainLayout);
  34. }
  35. static QString docTypeToString(DocType p_type)
  36. {
  37. QString str;
  38. switch (p_type) {
  39. case DocType::Html:
  40. str = "HTML";
  41. break;
  42. case DocType::Markdown:
  43. str = "Markdown";
  44. break;
  45. case DocType::List:
  46. str = "List";
  47. break;
  48. case DocType::Container:
  49. str = "Container";
  50. break;
  51. default:
  52. str = "Unknown";
  53. break;
  54. }
  55. return str;
  56. }
  57. void VTabIndicator::update(const VEditTabInfo &p_info)
  58. {
  59. const VEditTab *editTab = NULL;
  60. const VFile *file = NULL;
  61. DocType docType = DocType::Html;
  62. bool readonly = false;
  63. bool external = false;
  64. bool system = false;
  65. QString cursorStr;
  66. if (p_info.m_editTab)
  67. {
  68. editTab = p_info.m_editTab;
  69. file = editTab->getFile();
  70. docType = file->getDocType();
  71. readonly = !file->isModifiable();
  72. external = file->getType() == FileType::Orphan;
  73. system = external && dynamic_cast<const VOrphanFile *>(file)->isSystemFile();
  74. if (editTab->isEditMode()) {
  75. int line = p_info.m_cursorBlockNumber + 1;
  76. int col = p_info.m_cursorPositionInBlock;
  77. if (col < 0) {
  78. col = 0;
  79. }
  80. int lineCount = p_info.m_blockCount < 1 ? 1 : p_info.m_blockCount;
  81. QString cursorText = tr("<span><span style=\"font-weight:bold;\">Line</span>: %1 - %2(%3%) "
  82. "<span style=\"font-weight:bold;\">Col</span>: %4</span>")
  83. .arg(line).arg(lineCount)
  84. .arg((int)(line * 1.0 / lineCount * 100), 2)
  85. .arg(col, 3);
  86. m_cursorLabel->setText(cursorText);
  87. m_cursorLabel->show();
  88. } else {
  89. m_cursorLabel->hide();
  90. }
  91. }
  92. m_docTypeLabel->setText(docTypeToString(docType));
  93. m_readonlyLabel->setVisible(readonly);
  94. m_externalLabel->setVisible(external);
  95. m_systemLabel->setVisible(system);
  96. }