private void L_MouseLeave(object sender, EventArgs e) { // Get back original category color if (!(sender is Label l)) { return; } if (!(l.Tag is CitationCategory)) { l.BackColor = m_LabelDefaultColor; return; } string colorString = Categories.SingleOrDefault(x => x.Id == ((CitationCategory)l.Tag).CategoryId)?.CategoryColor; if (string.IsNullOrWhiteSpace(colorString)) { l.BackColor = m_LabelDefaultColor; return; } Color[] colors = ColorStuff.ConvertStringToColors(colorString); if (colors.Any()) { l.BackColor = colors[0]; } else { l.BackColor = m_LabelDefaultColor; } }
public Label CreateCategoryLabelControl(CitationCategory citCat, Category cat, ContextMenuStrip menu, ToolTip toolTip) { Label l = new Label(); Color[] color = ColorStuff.ConvertStringToColors(cat.CategoryColor); Color catColor = color.Any() ? color[0] : m_LabelDefaultColor; Font newFont = new Font("Times New Roman", 10, FontStyle.Regular); l.Font = newFont; l.MouseHover += L_MouseHover; l.MouseEnter += L_MouseEnter; l.MouseLeave += L_MouseLeave; l.AutoSize = true; l.BackColor = catColor; l.Text = $"{cat.Code} [{citCat.Weight}]"; l.ContextMenuStrip = menu; if (citCat.IsMain) { SetMainStyleOnLabel(l); } l.Tag = citCat; toolTip.SetToolTip(l, cat.Name + Environment.NewLine + cat.Description); return(l); }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0 || e.RowIndex >= dataGridView1.Rows.Count) { return; } if (e.ColumnIndex == 4) { Id id = (Id)dataGridView1.Rows[e.RowIndex].Cells[0].Value; Category cat = m_FilteredCategories.SingleOrDefault(x => x.Id == id); ColorDialog dlg = new ColorDialog(); Color[] colors = ColorStuff.ConvertStringToColors(cat.CategoryColor); dlg.Color = colors.Any() ? colors[0] : Color.White; DialogResult result = dlg.ShowDialog(this); if (result == DialogResult.Cancel) { return; } cat.CategoryColor = ColorStuff.ConvertColorsToString(new Color[] { dlg.Color }); m_CategoryService.InsertOrUpdate(cat); FireCategoryChanged(cat); dataGridView1.Rows[e.RowIndex].Selected = true; } }
private void DataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == 4) //foreach (DataGridViewRow Myrow in dataGridView1.Rows) { DataGridViewRow row = dataGridView1.Rows[e.RowIndex]; var colors = ColorStuff.ConvertStringToColors((string)row.Cells[ColorColIdx].Value); if (colors.Any()) { row.Cells[ColorColIdx].Style.BackColor = colors[0]; row.Cells[ColorColIdx].Style.ForeColor = colors[0]; row.Cells[ColorColIdx].Style.SelectionBackColor = colors[0]; row.Cells[ColorColIdx].Style.SelectionForeColor = colors[0]; } else { row.Cells[ColorColIdx].Style.BackColor = Color.White; row.Cells[ColorColIdx].Style.ForeColor = Color.White; row.Cells[ColorColIdx].Style.SelectionBackColor = Color.White; row.Cells[ColorColIdx].Style.SelectionForeColor = Color.White; } } }
public void RecreateTheWholeThing(ModelsForViewing vm, VolumeService volumeService) { string origFileName = vm.CurrentStorage.FilePath; string storageFilePath = System.IO.Path.Combine(m_UserSettingsService.StorageFolder, vm.CurrentStorage.StorageName); string newFileTmp = m_TempFileService.GetNewTmpFileName(vm.CurrentStorage.StorageName); //File.Copy(storageFilePath, tmpFileName, true); (int x, int y)offset = (volumeService.CurrentVolume.OffsetX, volumeService.CurrentVolume.OffsetY); PdfDocument pdfDoc = new PdfDocument(new PdfReader(origFileName), new PdfWriter(newFileTmp)); foreach (Citation cit in volumeService.Citations) { // Yeah, somtimes illegal citations end up in the database. if (cit.SelectionRects.Trim().Length < 5) { continue; } var cat = m_CategoryService.GetMainCategory(cit.Id); var citCat = m_CategoryService.GetMainCitationCategory(cit.Id); if (cat == null) { citCat.CategoryId = Id.Empty; } List <(int page, int[] rects)> pageRects = ArrayStuff.ConvertStringToPagesAndArrays(cit.SelectionRects); int firstPageNo = GetFirstPageFromPageRects(pageRects); Color color_highLight, color_underLine, color_margin = new DeviceRgb(n(255), n(255), n(255));; if (pageRects.Any()) { System.Drawing.Color ch, cu, cm; var colors = ColorStuff.ConvertStringToColors(cit.CitationColors); ch = (colors.Length >= 1) ? colors[0] : m_UserSettingsService.PdfHighLightColor; cu = (colors.Length >= 2) ? colors[1] : m_UserSettingsService.PdfUnderlineColor; cm = (colors.Length >= 3) ? colors[2] : m_UserSettingsService.PdfMarginBoxColor; color_highLight = new DeviceRgb(n(ch.R), n(ch.G), n(ch.B)); color_underLine = new DeviceRgb(n(cu.R), n(cu.G), n(cu.B)); color_margin = new DeviceRgb(n(cm.R), n(cm.G), n(cm.B)); foreach ((int page, int[] rects)pageRect in pageRects) { if (pageRect.rects.Count() < 4) // If no rects, for some reason... { continue; } //int currentPage = pageRects.First().page; int currentPage = pageRect.page; int currentRect = 0; bool notDone = true; do { PdfCanvas canvas1 = new PdfCanvas( pdfDoc.GetPage(currentPage).NewContentStreamBefore(), pdfDoc.GetPage(currentPage).GetResources(), pdfDoc); PdfCanvas canvas2 = new PdfCanvas( pdfDoc.GetPage(currentPage).NewContentStreamAfter(), pdfDoc.GetPage(currentPage).GetResources(), pdfDoc); Rectangle pageSize = pdfDoc.GetPage(firstPageNo).GetPageSize(); int pageHeight = (int)pageSize.GetHeight(); int pageWidth = (int)pageSize.GetWidth(); //canvas.SaveState(); canvas1.SetFillColor(color_highLight); canvas2.SetFillColor(color_underLine); do //(int i = 0; i < rects.Length; i += 4) { if (currentRect >= pageRect.rects.Length) // Sometime this is necessary, page rects are empty or broken. { break; } int x = pageRect.rects[currentRect] + offset.x; int y = pageHeight - pageRect.rects[currentRect + 1] - pageRect.rects[currentRect + 3] + offset.y; // Below text highlight canvas1.Rectangle(x, y, pageRect.rects[currentRect + 2], pageRect.rects[currentRect + 3]); canvas1.Fill(); // Above text underline canvas2.Rectangle(x, y, pageRect.rects[currentRect + 2], 1); canvas2.Fill(); if (currentRect + 5 > pageRect.rects.Length) { notDone = false; break; } // Detect page break int lastY = pageHeight - pageRect.rects[currentRect + 1] - pageRect.rects[currentRect + 3]; currentRect += 4; int newY = pageHeight - pageRect.rects[currentRect + 1] - pageRect.rects[currentRect + 3]; if (lastY < newY) { currentPage++; break; } } while (true); } while (notDone); } // Add annotation AddMarginBox(pdfDoc, null, firstPageNo, cit.Id.ToString(), cat.Code + $" [{citCat.Weight}]", cit.SelectionRects, color_margin, cit.MarginBoxSettings, offset); }// if pagerects.any } pdfDoc.Close(); // newFileTmp m_StorageHelperService.GetNextStorageFileName(vm.CurrentStorage); string newStoragePath = System.IO.Path.Combine(m_UserSettingsService.StorageFolder, vm.CurrentStorage.StorageName); int retries = 10; do { try { //File.Delete(storageFilePath); File.Copy(newFileTmp, newStoragePath); retries = 0; } catch { retries--; Thread.Sleep(500); } } while (retries > 0); File.Delete(newFileTmp); m_StorageHelperService.DeleteOldStorageFiles(newStoragePath); }